简体   繁体   中英

Httpclient GetAsync Fails(503 Service Unavailable) inside Web API on IIS Server

I have a simple web api that will retrieve a image file and return the bytes to the caller. It will work when I host the api project inside visualstudio in local (IIS Express), however, it will fail when I publish this project to my IIS server. Anyone has any idea?

[RoutePrefix("api/v1/Test")]
public class TestController : ApiController
{
    [Route("GetBytesCount")]
    public async Task<int> GetBytesCount()
    {
        var client = new HttpClient() { Timeout = new TimeSpan(0, 5, 0) };
        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

        var response = await client.GetAsync(@"http://icons.wxug.com/i/c/k/clear.gif");
        response.EnsureSuccessStatusCode();
        var imageBytes = await response.Content.ReadAsByteArrayAsync();
        return imageBytes.Length;
    }

}

if I called it from local box

http://localhost:57988/lkr/api/v1/Test/Getbytescount

it will return

int xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1689</int>

When I call it from my server, it will return

<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Response status code does not indicate success: 503 (Service Unavailable).
</ExceptionMessage>
<ExceptionType>System.Net.Http.HttpRequestException</ExceptionType>
<StackTrace>
......
</StackTrace>
</Error>

Go to the Project Properties.

Get SSL URL and use in your browser to access the resource.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM