var url = "http://xxx.123.123.ashx"; string str_postdata = JsonConvert.SerializeObject(new { method = "search",mID = "2113",language = 2052,pageNum = 1,pageSize = 30 }); httpWebRequest request = (httpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/Json;charset=utf-8"; request.ContentLength = EnCoding.UTF8.GetByteCount(str_postdata); string authStr = EncryptionUtil.MD5Encrypt32("abcdefg"); request.headers.Add("X","abc"); request.headers.Add("Y","def"); request.headers.Add("X-Auth-Value",authStr); Stream myRequestStream = request.GetRequestStream(); StreamWriter myStreamWriter = new StreamWriter(myRequestStream,EnCoding.GetEnCoding("gb2312")); myStreamWriter.Write(str_postdata); myStreamWriter.Close(); httpWebResponse response = (httpWebResponse)request.GetResponse(); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream,EnCoding.GetEnCoding("utf-8")); string retString = myStreamReader.ReadToEnd(); Object bupo = JsonConvert.DeserializeObject<Object>(retString); myStreamReader.Close(); myResponseStream.Close(); return bupo;总结
以上是内存溢出为你收集整理的c# 发送http请求并接收返回数据全部内容,希望文章能够帮你解决c# 发送http请求并接收返回数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)