码迷,mamicode.com
首页 > 其他好文 > 详细

如何在后台调用接口

时间:2016-11-24 19:29:50      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:read   local   post   byte   返回   end   bre   timeout   encode   

 string url = "http://localhost:12083/api/common/GetVerifyCode";
                string strType = "application/x-www-form-urlencoded";
                string strPar = "userName=18382565651";//拼接参数
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);//创建请求地址
                httpWebRequest.ContentType = strType;//设置http标头
                httpWebRequest.Method = "POST";//设置提交方式
                httpWebRequest.Timeout = 600000;//设置过期时间

                byte[] btBodys = Encoding.UTF8.GetBytes(strPar);//重写字符串为字节码
                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();
               

 

如何在后台调用接口

标签:read   local   post   byte   返回   end   bre   timeout   encode   

原文地址:http://www.cnblogs.com/woshizhaoji/p/6098782.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!