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.
My code is in the form of a C# Console Application
. The main part of my 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);
(The code above is called by the Main
method)
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.
However, when uploaded as an Azure webjob, I get this error:
An error occurred while sending the request.
Unable to connect to the remote server
An attempt was made to access a socket in a way forbidden by its access permissions xx.xx.xx.xxx:80
Any ideas on how to get past this? I'm looking for any possible solution/work-around.
An attempt was made to access a socket in a way forbidden by its access permissions xx.xx.xx.xxx:80
Per my understanding, I assumed that you may hit the outgoing connections limitation from Azure Web App sandbox. Also, I would recommend that you could scale your app hosting plan to larger instance for narrowing this issue.
Additionally, here are some similar issues, you could refer to them: