I have a Asp.Net Core (2.1) website using Asp.Net Boilerplate.
I'm trying to make a API call using HttpClient
, which works locally, but throws an error when deployed to IIS.
I created a TypedClient
public class FormsHttpClient : IFormsHttpClient
{
private const string url = "my_url:3001/";
private readonly HttpClient _client;
public FormsHttpClient(HttpClient httpClient)
{
httpClient.BaseAddress = new Uri(url);
_client = httpClient;
}
....
}
In my startup.cs
file, I added:
services.AddHttpClient<IFormsHttpClient, FormsHttpClient>();
The error i get when i deploy:
ERROR 2018-12-12 18:30:29,509 [11 ] Mvc.ExceptionHandling.AbpExceptionFilter - 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 System.Net.Http.HttpRequestException: 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 ---> System.Net.Sockets.SocketException: 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 at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken) --- End of inner exception stack trace ---
The network call normally takes 1800ms to finish, it seems to timeout around 21000ms.
I came across the code AppContext.SetSwitch("System.Net.Http.useSocketsHttpHandler", false);
, thought i wasn't sure where to put it, i tossed it in the constructor of my startup.cs
class but it doesn't seem to have any effect.
Is there something else im missing?
E: The code that calls the api is in JS:
app.forms.token = {
generate: function () {
Formio.logout();
abp.services.app.forms.generateFormToken().done(function (e) {
Formio.setToken(e);
});
},
clear: function () {
Formio.logout();
}
}
500
@gabriel, i can make the same api call in postman from the same device, so i can definitely access it. It seems the be the failing on anyHttpClient's
PostAsync
orGetAsync
, depending on which call i make – lizzy91