【问题标题】:Azure WebSites -> Call between two WebAPIsAzure 网站 -> 两个 WebAPI 之间的调用
【发布时间】:2015-03-20 14:07:49
【问题描述】:

我有两个在 Azure 网站上运行 CoreCLR 的 ASP.NET vNext Web 应用程序,由最新的 Visual Studio 2015 CTP 发布。 当我尝试使用标准 HttpClient 代码从一个应用程序调用第二个应用程序时:

        using (var client = new HttpClient())
        {
            client.BaseAddress = new Uri(_webUri);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpContent contentPost = new StringContent(request.ToJson(), Encoding.UTF8, "application/json");
            var response = await client.PostAsync(uri, contentPost);//.PostAsJsonAsync("api/products", request);
            if (response.IsSuccessStatusCode)
            {
                   ...
            }
        }

我得到以下异常:

WinHttpException: An attempt was made to access a socket in a way forbidden by its access permissions.
   System.Net.Http.WinInetProxyHelper.GetProxyForUrl(SafeInternetHandle sessionHandle, Uri uri, WINHTTP_PROXY_INFO& proxyInfo)

HttpRequestException: An error occurred while sending the request.
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

我在 Azure 网站 ftp 上的 web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="kpm-package-path" value="..\approot\packages" />
    <add key="bootstrapper-version" value="1.0.0-beta2" />
    <add key="kre-package-path" value="..\approot\packages" />
    <add key="kre-version" value="1.0.0-beta2" />
    <add key="kre-clr" value="CoreCLR" />
    <add key="kre-app-base" value="..\approot\src\Ingrid.Web" />
  </appSettings>
</configuration>

【问题讨论】:

  • 这些是WebRoles 还是Websites?您传入的_webUri 的格式是什么?
  • @BrendanGreen 海报明确指出网站不是云服务。
  • 是的,它是 Azure 网站 - 我有一个关于云服务的堆栈溢出的单独问题,因为目前云服务似乎根本不支持 vnext,至少从 VS2015 开始。
  • _webUri 是标准的 WebAPI Uri,例如 http://some.domain/api/controller/action
  • 您的 web.config 中有默认代理吗?

标签: c# azure asp.net-web-api azure-web-app-service asp.net-core


【解决方案1】:

我找到的解决方案:https://github.com/sendgrid/sendgrid-csharp/issues/18

使用 RestSharp 比使用 HttpClient 更好,它确实有效:http://restsharp.org/

【讨论】:

    猜你喜欢
    • 2021-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-21
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多