c#的httpWebRequest(2)
2021-07-16 12:15
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;
}
上一篇:Windows命令
下一篇:百度地图API 路线模拟