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?
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.