c# 发送http请求并接收返回数据

c# 发送http请求并接收返回数据,第1张

概述var url = "http://xxx.123.123.ashx"; string str_postdata = JsonConvert.SerializeObject(new { method = "search", mid = "2113",
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请求并接收返回数据所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1232579.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存