/// <summary>///body是要传递的参数,格式"roleId=1&uid=2"///post的cotentType填写"application/x-www-form-urlencoded"///soap填写 ...
/// <summary>///body是要传递的参数,格式"roleId=1&uid=2"///post的cotentType填写"application/x-www-form-urlencoded"///soap填写:"text//// </summary>public static get='_blank'>string PostHttp(string url, string body, string contentType) { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.ContentType = contentType; httpWebRequest.Method = "POST"; httpWebRequest.Timeout = 20000; byte[] btBodys = Encoding.UTF8.GetBytes(body); httpWebRequest.ContentLength = btBodys.Length; httpWebRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length); HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()); string responseContent = streamReader.ReadToEnd(); httpWebResponse.Close(); streamReader.Close(); httpWebRequest.Abort(); httpWebResponse.Close(); return responseContent; }
原标题:C#通过WebClient/HttpWebRequest实现http的POST/GET方法
关键词:C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。