简体   繁体   中英

Unreachable endpoint from Azure

I am trying to reach an endpoint hosting a json from an Azure function. I can access the url from my machine in a browser or when executing the code. But from Azure I keep getting a 406. the code is pretty simple and as follow:

var client = new HttpClient();
client.DefaultRequestHeaders
      .Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.GetAsync(endpointurl);
response.EnsureSuccessStatusCode();

this keeps giving me the 406 when hosted on Azure, not on local ... Any idea how to get more information? How to debug/fix that?

Thanks

406 is one of the HTTP Response Status codes which indicates that something is NOT ACCEPTABLE.

From you code we are requesting something with Accept header, but the server is unable to fulfill it.

Also, as 406 will comes under 4XX which is client error responses.

In our case, we are requesting a specific content type to be returned by the server. For ex: Accept: application/json or application/xml , so here server is unable to respond to the matching content type that was requested. This leads to throwing a 406 Not Acceptable error .

Most possible situation of cause the error is with the endpoint URL and it show have access to it. As you mentioned that it is working on local, there should be some parameters assigning. Like adding connections like local.settings.json to Application settings in Azure portal, CORS to your endpoint..

Check for private endpoint info from MS Docs

To understand more about 406 Not Acceptable Error refer to blog, thanks to airbrake.io

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM