1. 程式人生 > >c#的httpWebRequest(2)

c#的httpWebRequest(2)

ons [] read urlencode method web return code sts

public string httpWebservice(string url, string body)
{
string rootUrl = ConfigHelper.AppSettings("RemoteHttpURL");
WebRequest wRequest = WebRequest.Create(rootUrl + url);
wRequest.Method = "POST";
wRequest.Timeout = 20000;
wRequest.ContentType = "application/x-www-form-urlencoded";

byte[] btBodys = Encoding.UTF8.GetBytes(body);
wRequest.ContentLength = btBodys.Length;
wRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length);

WebResponse wResponse = wRequest.GetResponse();
Stream stream = wResponse.GetResponseStream();
StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8);
string str = reader.ReadToEnd(); //url返回的值
reader.Close();
wResponse.Close();
return str;
}

c#的httpWebRequest(2)