alek kowalczyk
alek kowalczyk

Reputation: 4934

Azure WebSites -> Call between two WebAPIs

I have two ASP.NET vNext Web Applications running with CoreCLR on Azure WebSites, published by the lates Visual Studio 2015 CTP. When I'm trying to make a call from one application to the second with standard HttpClient code:

        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)
            {
                   ...
            }
        }

I get following exception:

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)

my web.config on the azure websites 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>

Upvotes: 0

Views: 536

Answers (1)

alek kowalczyk
alek kowalczyk

Reputation: 4934

Solution which I found on: https://github.com/sendgrid/sendgrid-csharp/issues/18

it's better to go with RestSharp than HttpClient, and it is indeed working: http://restsharp.org/

Upvotes: 0

Related Questions