服务器异常OperationCanceledException发生在Microsoft.Owin.IOwinContextExtensions.GetDependencyResolver

时间:2019-04-20 14:24:36

标签: c# xamarin asp.net-web-api2

我有一个可以使用此cURL命令调用的api:

 C:\Windows\System32\curl.exe -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Bearer X.Y.Z -d '{
 >>    "Filter": {
 >>      "ShowRent": true,
 >>      "ShowSale": true,
 >>      "ShowApartment": true,
 >>      "ShowOffice": true,
 >>    },
 >>    "PageSize": 1,
 >>    "PageNumber": 1
 >>  }'  http://localhost:port_number/path_to_api

此请求已成功完成。
该api应该返回一个List<ResultDto>
我想在Xamarin项目中创建相同的请求。
这是我尝试过的:

var a = new
    {
        PageSize = 5,
        PageNumber = 1,
        Filter = new
        {
            ShowRent = true,
            ShowSale = true,
            ShowApartment = true,
            ShowOffice = true
         }
    };
    var json = JsonConvert.SerializeObject(a);
    var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
    var client = new HttpClient();
    client.DefaultRequestHeaders.Authorization =
        new AuthenticationHeaderValue(
            "Bearer",
            my_access_token);
    var rawResponse = await client.PostAsync(
        "http://localhost:port_number/path_to_api",
        stringContent
        );

    List<RealtorEstateMarkerDto> result=
        JsonConvert.DeserializeObject<List<ResultDto>>(
            await rawResponse.Content.ReadAsStringAsync());

运行我的xamarin代码时,服务器上发生System.OperationCanceledException异常。

这是异常的堆栈跟踪:

at System.Threading.CancellationToken.ThrowOperationCanceledException()
at System.Threading.CancellationToken.ThrowIfCancellationRequested()
at Microsoft.Owin.IOwinContextExtensions.GetDependencyResolver(IOwinContext context)

0 个答案:

没有答案