为什么它发出请求的两倍 [英] why is it making the request twice

查看:185
本文介绍了为什么它发出请求的两倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这code被写入到发送请求到服务并接收简单的JSON响应,但该服务的服务器日志显示正在以1秒钟的延迟要求它的两倍。我无法弄清楚为什么会发生这种code发出请求两次请指导我,如果有一些配置丢失。

this code is written to send request to a service and receive simple json response but the service's server log shows that it is being requested twice with a delay of 1 second. I cant figure it out why does this code make the request twice please guide me if there is some configuration missing.

string StrUrl = @"http://www.myapp.com/Tracker.json";
Uri uri1 = new Uri(StrUrl);
HttpWebRequest webRequest1 = (HttpWebRequest)HttpWebRequest.Create(uri1);
webRequest1.ServicePoint.ConnectionLimit = 1;
webRequest1.Timeout = 50000;
webRequest1.ReadWriteTimeout = 50000
webRequest1.PreAuthenticate = false;
webRequest1.Proxy = null;
webRequest1.CookieContainer = cookieJar;
webRequest1.Method = "POST";
webRequest1.KeepAlive = false;

WebResponse response1 = webRequest1.GetResponse();

StreamReader streamReader1 = new StreamReader(response1.GetResponseStream());
String responseData1 = streamReader1.ReadToEnd();

这可能是类似的问题。

these might be similar problems

<一个href=\"http://stackoverflow.com/questions/6338942/why-my-http-client-making-2-requests-when-i-specify-credentials?rq=1\">Why我的HTTP客户端做2请求时,我指定凭据?

<一个href=\"https://social.msdn.microsoft.com/Forums/vstudio/en-US/dad87752-42dd-4346-a1c5-da30f6156406/why-httpwebrequest-send-data-twice-in-https\" rel=\"nofollow\">https://social.msdn.microsoft.com/Forums/vstudio/en-US/dad87752-42dd-4346-a1c5-da30f6156406/why-httpwebrequest-send-data-twice-in-https

推荐答案

这个问题通过使用 RestSharp(简单的REST和HTTP API客户端解决.NET)

var client = new RestClient("http://www.myapp.com/Tracker.json");
// client.Authenticator = new HttpBasicAuthenticator(username, password);

var request = new RestRequest("", Method.POST);

// execute the request
RestResponse response = client.Execute(request);
var content = response.Content; // raw content as string

阅读这篇文章的Web客户端的比较,HttpClient的HttpWebRequest的和

read this article for comparison of WebClient, HttpClient and HttpWebRequest

这篇关于为什么它发出请求的两倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆