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

使用HttpClient发送GET请求

时间:2014-07-11 10:26:57      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   使用   line   

HttpRequestMessage http_req_msg = new HttpRequestMessage();
http_req_msg.Method = HttpMethod.Get;
http_req_msg.Headers.Add("user-agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
http_req_msg.RequestUri = new Uri("http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl");                       

HttpClient httpclient;            
HttpClientHandler httphandler;            

httphandler = new HttpClientHandler();
httphandler.AllowAutoRedirect = false;
httphandler.UseCookies = false;

httpclient = new HttpClient(httphandler);
var task = httpclient.SendAsync(http_req_msg);
task.Result.EnsureSuccessStatusCode();

HttpResponseMessage response = task.Result;

var result = response.Content.ReadAsStringAsync();
string responseBodyAsText = result.Result;
responseBodyAsText = responseBodyAsText.Replace("<br>", Environment.NewLine); // Insert new lines

MessageBox.Show(responseBodyAsText);

 

使用HttpClient发送GET请求,布布扣,bubuko.com

使用HttpClient发送GET请求

标签:style   blog   http   color   使用   line   

原文地址:http://www.cnblogs.com/lijiu/p/3834296.html

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