连接尝试失败,因为连接方未正确响应 [英] A connection attempt failed because the connected party did not properly respond
问题描述
我在1and1上有一个共享服务器.在我的MVC站点中,当我尝试连接到外部的其他服务器时,出现此错误:
I have a shared server on 1and1. In my MVC site, when I try to connect to another server outside I get this error:
发送请求时发生错误.无法连接到 远程服务器连接尝试失败,因为连接方 一段时间后未正确响应,或已建立 连接失败,因为连接的主机无法响应 23.xxx.xxx.xxx:80
An error occurred while sending the request. Unable to connect to the remote server 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 23.xxx.xxx.xxx:80
当我在本地开发计算机上运行它时,它可以正常工作,但是当我通过FTP将其上传到服务器时,它会显示该错误.
When I run it on my development machine locally it works fine, but when I upload it to server by FTP, it shows that error.
这是我的代码:
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://OutsideServer.com", UriKind.Absolute);
var url = "GetData";
var stringContent = string.Format("\"id\":12");
StringContent content = new StringContent(stringContent);
var result = await client.PostAsync(url, content);
var jsondata = await result.Content.ReadAsStringAsync();
in another question I found this answer:
<configuration>
<system.net>
<defaultProxy>
<proxy
usesystemdefault = "false"
proxyaddress="http://proxyserver"
bypassonlocal="true"
/>
</defaultProxy>
</system.net>
</configuration>
但是我不知道应该使用什么代理地址.
But I don't know what proxy address should be.
推荐答案
5年后,我试图将它与asp.net core 3.1 mvc应用程序一起使用时遇到了相同的问题.我在他们的网站
I ran into the same issue after 5 years when trying to use it with asp.net core 3.1 mvc app. I used the following proxy setting as mentioned in their site https://www.ionos.co.uk/help/hosting/net/script-examples-for-establishing-external-http-connections-windows/
<proxy proxyaddress="http://winproxy.server.lan:3128"
bypassonlocal="true"
/>
httpclient现在看起来像这样,并且可以正常工作.希望它能对某人有所帮助.
The httpclient now looks like this and it works. Hope it might help someone.
services.AddHttpClient<MyNamedClient>()
.ConfigureHttpClient((provider, httpClient) =>
{
})
.ConfigurePrimaryHttpMessageHandler((handler) => new HttpClientHandler {
UseDefaultCredentials=true,
Proxy = new WebProxy("http://winproxy.server.lan:3128",true)
});
这篇关于连接尝试失败,因为连接方未正确响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!