一般的QueryString就直接在網址加參數就好
但如果是用Post的話則要用下面方法
public Stream GetWebData(string Url, string PostData)
{
byte[] myData = Encoding.Default.GetBytes(PostData);
HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(Url);
myRequest.Method = "POST";
myRequest.Accept = "*/*";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = myData.Length;
Stream myStream = myRequest.GetRequestStream();
myStream.Write(myData, 0, myData.Length);
myStream.Close();
HttpWebResponse myResponse;
try { myResponse = (HttpWebResponse)myRequest.GetResponse(); }
catch (Exception) { return null; }
ResponseStream = myResponse.GetResponseStream();
return ResponseStream;
}
上面函式的第一個參數Url就傳網址
上面函式的第二個參數PostData
就傳像下面這樣
string myPost = "";
myPost += "?area=" + "東北亞";
myPost += "&city1=" + "東京";
myPost += "&city2=" + "秋葉原";
myPost += "&name=" + "welkingunther";