首页 > 其他 > 详细

如何在后台调用接口

时间:2016-11-24 19:27:51      阅读:320      评论:0      收藏:0      [点我收藏+]
 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();
               

 

如何在后台调用接口

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!