我有一个简单的 web api,它将检索图像文件并将字节返回给调用者。当我在本地(IIS Express)的visualstudio中托管api项目时它会起作用,但是当我将此项目发布到我的IIS服务器时它会失败。有人有什么想法吗?
[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;
}
}
如果我从本地盒子里调用它
http://localhost:57988/lkr/api/v1/Test/Getbytescount
它会回来
int xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1689</int>
当我从我的服务器调用它时,它会返回
<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>