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

发送请求获取响应内容

时间:2018-11-25 13:23:39      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:type   creat   turn   for   encode   bre   image   bsp   keepalive   

C#请求url,获取响应的脚本

 

public string ResultOfApi(string url)
        {
            //发送请求
            HttpWebRequest request = null;
            HttpWebResponse response = null;
            request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Method = "Get";
            request.ContentType = "application / x - www - form - urlencoded";
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
            request.Accept = "text / html,application / xhtml + xml,application / xml; q = 0.9,image / webp,image / apng,*/*;q=0.8";
            request.KeepAlive = true;
            //获取响应
            response = (HttpWebResponse)request.GetResponse();
            Stream S = response.GetResponseStream();
            StreamReader streamreader = new StreamReader(S);
            string result = streamreader.ReadToEnd();
            return result
        }

 

发送请求获取响应内容

标签:type   creat   turn   for   encode   bre   image   bsp   keepalive   

原文地址:https://www.cnblogs.com/dinghanhua/p/10015201.html

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