A connection attempt failed because the connected party did not properly respond

被刻印的时光 ゝ 提交于 2020-08-09 14:00:51

问题


I have a shared server on 1and1. In my MVC site, when I try to connect to another server outside I get this error:

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

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.

here is my code:

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.


回答1:


This is a 1&1 issue - they don't allow you to connect to servers outside their network :( had the same issue when calling a PayPal API. If you ring their support and explain they may take pity on you, but they didn't on me!

Update - found this from when I was digging around with Paypal last - this guy says you can create a proxy withing 1&1 - I haven't used this method myself: http://tofuculture.com/blog/post/Tips-Tricks-of-Using-11-Shared-Hosting-Environment.aspx




回答2:


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"
        />

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)
                    });


来源:https://stackoverflow.com/questions/25721804/a-connection-attempt-failed-because-the-connected-party-did-not-properly-respond

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!