title: Azure Webjob: An attempt was made to access a socket in a way forbidden by its access permissions x.x.x.x:80
body: <p>I know there's a couple questions so far involving this error - but nobody has generated this error yet due to a webjob on Azure.</p>
  
  <p>My code is in the form of a C# <code>Console Application</code>. The main part of my code:</p>
  
  <pre><code>HttpClient client = new HttpClient();
  var byteArray = Encoding.ASCII.GetBytes("user:password");
  client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
  HttpResponseMessage response = await client.GetAsync("http://xx.xx.xx.xxx/cgi-bin/snapshot.cgi?channel=0");
  byte[] myBytes = await response.Content.ReadAsByteArrayAsync();
  string convertedFromString = Convert.ToBase64String(myBytes);
  </code></pre>
  
  <p>(The code above is called by the <code>Main</code> method)</p>
  
  <p>If executed on my local machine it works just fine. If I add this code to an API method used by an App Service (part of an ASP.Net Core project), it also works.</p>
  
  <p>However, when uploaded as an Azure webjob, I get this error:</p>
  
  <blockquote>
    <p>An error occurred while sending the request.</p>
    
    <p>Unable to connect to the remote server</p>
    
    <p>An attempt was made to access a socket in a way forbidden by its
    access permissions xx.xx.xx.xxx:80</p>
  </blockquote>
  
  <p>Any ideas on how to get past this? I'm looking for any possible solution/work-around.</p>