I am having an issue :
我有一个问题:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond URL.
连接尝试失败,因为连接方在一段时间后没有正确响应,或者建立的连接失败,因为连接的主机无法响应URL。
Also I get issue like:
我也得到如下问题:
System.IO.IOException: Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host
System.IO.IOException:无法将数据写入传输连接:远程主机强制关闭现有连接
and
System.Net.WebException: The operation has timed out at System.Net.WebClient.UploadFile(Uri address, String method, String fileName)
System.Net.WebException:操作已在System.Net.WebClient.UploadFile超时(Uri地址,String方法,String fileName)
I know that this question has asked before but believe me I tried almost every single resolution at my end.
我知道这个问题以前曾经问过,但是相信我,我几乎尝试过每一个决议。
Weird thing is this issue does not appear at my end at all and only when client try to use which is not constant. Some time my application works fine at their end too.
奇怪的是这个问题根本没有出现在我的最后,只有当客户端尝试使用哪个不是常量时。有一段时间我的应用程序也可以正常工作。
What I am trying to accomplish is I have created an desktop application (Win Forms & C#) and trying to login client while sending request to my php api server which is hosted on GODaddy.
我想要完成的是我创建了一个桌面应用程序(Win Forms&C#)并尝试登录客户端,同时向我的php api服务器发送请求,该服务器托管在GODaddy上。
var request = (HttpWebRequest)WebRequest.Create("url");
if (request != null)
{
#region System.Net.WebException
request.Method = "POST";
if (!string.IsNullOrEmpty(body))
{
var requestBody = Encoding.UTF8.GetBytes(body);
request.ContentLength = requestBody.Length;
request.ContentType = "application/json";
using (var requestStream = request.GetRequestStream())
{
requestStream.Write(requestBody, 0, requestBody.Length);
}
}
else
{
request.ContentLength = 0;
}
request.Timeout = 15000;
request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.BypassCache);
string output = string.Empty;
try
{
using (var response = (HttpWebResponse)request.GetResponse())
{
using (var stream = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1252)))
{
if (response.StatusCode == HttpStatusCode.OK)
{
while (!stream.EndOfStream)
{
output += stream.ReadLine();
}
output = stream.ReadToEnd();
}
}
}
Please help me out.
请帮帮我。
Thanks in advance.
提前致谢。
2 个解决方案
#1
0
Try adding this...
尝试添加此...
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.ServicePoint.ConnectionLimit = 12;
MSDN article recommends 12 connections per CPU hence the limit of 12 because it's hosted by GoDaddy so I'm sure the server resources are limited.
MSDN文章建议每个CPU有12个连接,因此限制为12,因为它由GoDaddy托管,所以我确定服务器资源是有限的。
#2
0
I think I got the answer. Thought to post it so that it could help anyone else.
我想我得到了答案。想发布它以便它可以帮助其他人。
It most probably the particular machine issue or server issue but in my case, I tried to set Request.proxy = null and it worked like a charm.
它很可能是特定的机器问题或服务器问题,但在我的情况下,我试图设置Request.proxy = null,它就像一个魅力。
#1
0
Try adding this...
尝试添加此...
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.ServicePoint.ConnectionLimit = 12;
MSDN article recommends 12 connections per CPU hence the limit of 12 because it's hosted by GoDaddy so I'm sure the server resources are limited.
MSDN文章建议每个CPU有12个连接,因此限制为12,因为它由GoDaddy托管,所以我确定服务器资源是有限的。
#2
0
I think I got the answer. Thought to post it so that it could help anyone else.
我想我得到了答案。想发布它以便它可以帮助其他人。
It most probably the particular machine issue or server issue but in my case, I tried to set Request.proxy = null and it worked like a charm.
它很可能是特定的机器问题或服务器问题,但在我的情况下,我试图设置Request.proxy = null,它就像一个魅力。