string strURL = "
http://localhost:2852/WebSite1/Service1.asmx/doSearch";
System.Net.HttpWebRequest request;
request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strURL);
//Post请æ±æ¹å¼
request.Method = "POST";
// å
容类å
request.ContentType = "application/x-www-form-urlencoded";
//è¿æ¯åå§ä»£ç ï¼
string paraUrlCoded = "p1=x&p2=y&p3=æµè¯çä¸æ";
byte[] payload;
//å°URLç¼ç åçå符串转å为åè
payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
//设置请æ±ç ContentLength
request.ContentLength = payload.Length;
//è·å¾è¯· æ±æµ
Stream writer = request.GetRequestStream();
//å°è¯·æ±åæ°åå
¥æµ
writer.Write(payload, 0, payload.Length);
// å
³é请æ±æµ
writer.Close();
System.Net.HttpWebResponse response;
// è·å¾ååºæµ
response = (System.Net.HttpWebResponse)request.GetResponse();
System.IO.Stream s;
s = response.GetResponseStream();
XmlDocument d = new XmlDocument();
d.Load(s);
MessageBox.Show(d.DocumentElement.InnerText);