如何实现HTTP请求
参数:url:目标地址data:要post的数据比如a=1&b=2publicstringGetPostString(stringurl,stringdata){try{byte[]postBytes=Encoding.GetEncoding("utf-8").GetBytes(data);HttpWebRequestmyRequest=(HttpWebRequest)WebRequest.Create(url);myRequest.Method="POST";myRequest.ContentType="text/html";myRequest.ContentLength=postBytes.Length;myRequest.Proxy=null;StreamnewStream=myRequest.GetRequestStream();newStream.Write(postBytes,0,postBytes.Length);newStream.Close();//GetresponseHttpWebResponsemyResponse=(HttpWebResponse)myRequest.GetResponse();using(StreamReaderreader=newStreamReader(myResponse.GetResponseStream(),Encoding.GetEncoding("utf-8"))){stringcontent=reader.ReadToEnd();returncontent;}}catch(System.Exceptionex){returnex.Message;}}