0

I was create simple project with .netCore 2.0 and send HttpRequest with HttpClient, that is working well.

But, when I'm migrating from .netCore 2.0 to upper version ( e.g: .NetCore 2.1 or .netCore 3.0 ) this Code is not working.

My Code is:

public async Task<bool> IsValid()
    {
        string url = "http://api.domain.com/...";
        var values = new Dictionary<string, string>()
            {
               { "param1", "value1" },
               { "param2", "value2" }
            };

        HttpClient client = new HttpClient();

        var content = new FormUrlEncodedContent(values);
        var post = await client.PostAsync(url, content);
        if (post.StatusCode == System.Net.HttpStatusCode.OK)
        {
            return true;
        }
        return false;
    }

I expect the output of httpResponse to bo HttpStatusCode.OK. but the actual output is HttpStatusCode.GatewayTimeout.

I found that: If I run API server ( http://api.domain.com/ ) in IIS of windows server 2012, all requests is working well. But When I Use IIS of Windows 8, only HttpRequest with ASP.NET Core sdk 2.0 is working and others not working.

Can anyone help me?

AminRostami
  • 2,585
  • 3
  • 29
  • 45
  • How are you running this? .NET Core Console? ASP.NET Core? What SDK's are you using? What are you using to debug this? – Tubs Apr 23 '19 at 15:53
  • I use .Net core sdk 2.1 in ASP.NET Core application. (I also Test in asp.net core 2.2 and 3.0 but not working). I call this method from controller. – AminRostami Apr 23 '19 at 17:12
  • Have you enabled `Development time IIS support`? We have had issues in the past as well where the SDK hasn't installed the runtime correctly so it works in development but not when we deploy to a site with IIS – Tubs Apr 24 '19 at 08:09
  • I test this method in Developmet Mode. – AminRostami Apr 24 '19 at 09:13
  • 1
    I test this method in Developmet Mode, and `IIS` Complete installed in `Windows 8`. But `Development time IIS support` not installed in `vs Installer`, this feature is optional. I install this feature and test again. thanks for help. – AminRostami Apr 24 '19 at 09:23
  • No problem. Let me know if it works. – Tubs Apr 24 '19 at 10:38
  • Hi Tubs. I install those features in `vs 2019` and test again. But that is not working. I still have that error. – AminRostami Apr 27 '19 at 03:29
  • 1
    I think that is related to `iis setup` in `win 8`. – AminRostami Apr 27 '19 at 04:16

1 Answers1

0

This problem has finally been resolved.

This problem was related to the network and proxy settings in my network.

I realize when api server be in internet network, that is working well. but when api server to be used in local network, Because of using the proxy in my network, all requests was encountered with error 504 (unless the request was sending with .netCore sdk 2.0 ).

It should be noted I had added this line 192.168.11.125 api.domain.com to host file in Directory c:\windows\system32\drivers\etc\hosts. and also, I had added Follow Exceptions: 192.168.11.125 api.domain.com from path:

Control Panel > Network and Internet > Internet Option > Connections Tab > Lan Settings > Advanced > Exceptions panel

But that's not working.

When I picked up the check of Use a proxy server for your lan ... in Local Area Network (LAN) Settings form, all requests working well.

Of course, this question remains that, why The same request is working with .netcore sdk 2.0 ?

what is difference between sending request with .netCore sdk 2.0 and (.netCore sdk 2.1 or .netCore sdk 2.2 or .netCore sdk 3.0)???!!!

Good luck.

AminRostami
  • 2,585
  • 3
  • 29
  • 45