Azure 网站 -> 两个 WebAPI 之间的调用

Azure WebSites -> Call between two WebAPIs

我在 Azure 网站上有两个 ASP.NET vNext Web 应用程序 运行 CoreCLR,由最新的 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)

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

<?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>

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

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