首页 > 代码库 > 使用HttpClient发送GET请求
使用HttpClient发送GET请求
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 linesMessageBox.Show(responseBodyAsText);
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。