Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# IIS服务器上的Web API中的Httpclient GetAsync失败(503服务不可用)_C#_Asp.net Web Api_Httpclient_Getasync - Fatal编程技术网

C# IIS服务器上的Web API中的Httpclient GetAsync失败(503服务不可用)

C# IIS服务器上的Web API中的Httpclient GetAsync失败(503服务不可用),c#,asp.net-web-api,httpclient,getasync,C#,Asp.net Web Api,Httpclient,Getasync,我有一个简单的web api,它将检索图像文件并将字节返回给调用者。当我在本地(IIS Express)的visualstudio中托管api项目时,它会工作,但是,当我将此项目发布到IIS服务器时,它会失败。有人知道吗 [RoutePrefix("api/v1/Test")] public class TestController : ApiController { [Route("GetBytesCount")] public async Task<int> Ge

我有一个简单的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;
    }

}
它会回来的

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>
intxmlns=”http://schemas.microsoft.com/2003/10/Serialization/">1689
当我从服务器调用它时,它将返回

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>

发生了一个错误。
响应状态代码不表示成功:503(服务不可用)。
System.Net.Http.HttpRequestException
......

转到项目属性

获取SSL URL并在浏览器中使用以访问资源


作为一个不相关的旁注,您应该使用
response.Content.ReadAsByteArrayAsync()
请不要删除堆栈跟踪…堆栈跟踪指向代码中的行号…@Matias Cicero,我同意,我将更改代码。服务器上的事件日志中是否有条目?@Hackerman这是行“response.EnsureSuccessStatusCode();“引发异常。http状态代码为503。