1
votes

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.

2
could you access OutsideServer.com from outside of your local network? Try to type nslookup -type=A nslookup -type=A OutsideServer.com into command line and see if it works.Marian Ban
@MajoB yes it works. returns an address in this format 23.xx.xxx.xxxuser3293835
@user3293835 did you get the answer after 5 years? because I am having exact the same issue using 1and1 serviceLong Luong

2 Answers

1
votes

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

1
votes

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