Request timeout for HttpClient


I am working in TypeScript with ASP.NET Core Web API.


I am working with a large data response service on the backend side. That took more than two minutes to load the data. As I know the default timeout for HttpClient is for two minutes for localhost
(Chrome hold for request time out), but when I publish my code to the IIS site, after two minutes it gives a 500 Internal Server Error.

On the API side:

I have set the time to 1000 seconds.

 services.AddDbContext<BusinessContext>(options =>
     options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"], opts => opts.CommandTimeout(1000).EnableRetryOnFailure()));

On the web side:

Try 1:

This is a simple service call

async getData(lookUp: Lookup): Promise<PacketSearchItem[]> {
    return await + "Packet/ManualSearch", lookUp)
      .toPromise() as PacketSearchItem[];

Try: 2

async getData(lookUp: Lookup): Promise<PacketSearchItem[]> {
    return await + "Packet/ManualSearch", lookUp).pipe(timeout(10000000))
      .toPromise() as PacketSearchItem[];

Try: 3

async getData(lookUp: Lookup): Promise<PacketSearchItem[]> {
    return await + "Packet/ManualSearch", lookUp, { headers: new HttpHeaders({ timeout: `${10000000}` })}).pipe(timeout(10000000))
      .toPromise() as PacketSearchItem[];

Research on Google:


I used the upper link code to, but it gives me the same error, because after 2 minutes a request time out occur in Google Chrome.

Error Screenshot:

1) Console Error:

Enter image description here

2.) Network Error:

Enter image description here

I want to wait for Chrome to get the response from the API.

I already added the CORS policy:

 services.AddCors(options => {
         builder => builder.AllowAnyOrigin()

    builder => {
            async context => {
                context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                context.Response.Headers.Add("Access-Control-Allow-Origin", "*");

                var error = context.Features.Get<IExceptionHandlerFeature>();
                if (error != null) {
                    context.Response.Headers.Add("Application-Error", error.Error.Message);
                    // CORS
                    context.Response.Headers.Add("access-control-expose-headers", "Application-Error");

                    await context.Response.WriteAsync(error.Error.Message).ConfigureAwait(false);


After a lot of research I found the answer. It is problem in a ASP.NET Core configuration file:


 <aspNetCore requestTimeout="00:20:00">

We have to increase the time-out here.

Helping link:


Answered By – Harshad Pansuriya

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published