使用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 lines MessageBox.Show(responseBodyAsText);
上一篇:ERROR 1045 (28000): Access denied for user root@localhost (using password:


下一篇:Python 查看本机WiFi密码