C# HttpResponse returns statuscode 406 Not Acceptable

254 Views Asked by At

I have created an Azure Function which connects to an API. This is the code:

public static async Task<HttpResponse> RunProduction(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
    _log = log;
    API_URL = @"{API_URL}";
    BEARER_TOKEN = Environment.GetEnvironmentVariable("{ENV_NAME}");
    if (BEARER_TOKEN.Equals("")) throw new Exception("Bearer token could not be retrieved");

    var response = req.HttpContext.Response;
    response.Clear();
    response.StatusCode = 200;
    response.ContentType = "text/plain";

    //This is where the API will be called.
    //The method is not changing anything in the response (yet)
    response = await ExecuteMethods(req, response); 

    return response;
}

I am testing the Function locally with Postman. In Postman, I have the following headers: Postman header information

Every time I test the Function, I receive a 406 Not Acceptable. This even happens when I comment the line where the method ExecuteMethods() is being called. Any ideas how I can get rid of the 406-error and get my 200-statuscode again?

0

There are 0 best solutions below