title: Azure Function POST request shows as unauthorized when testing from Swagger
body: <p>I have created an azure function (HTTP triggered with Open API) and deployed to azure. The endpoints working good. I am getting response when testing from Postman</p>
  <p>Swagger UI also loading. But when trying to post from Swagger it keeps saying 401 unauthorized. But I have copied the function key from Azure portal (below screen shot) and specified that in authorize popup with in swagger.</p>
  <p><a href="https://i.stack.imgur.com/cOUKf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cOUKf.png" alt="enter image description here" /></a></p>
  <p>But it still saying unauthorized.</p>
  <p>When I copy the URL from portal for the http endpoint, it looks like this</p>
  <p><a href="https://myurls-asev3.appserviceenvironment.net/api/ObjectRead?code=mycode" rel="nofollow noreferrer">https://myurls-asev3.appserviceenvironment.net/api/ObjectRead?code=mycode</a></p>
  <p>Here mycode is exactly the same one I copied from function keys. But the only difference is, the code is attached as a query string in url when I copied the URL from portal
  <a href="https://i.stack.imgur.com/cYUho.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cYUho.png" alt="enter image description here" /></a></p>
  <p>But in swagger it sends as header.</p>
  <p>But in function configuration I designed it to accept as header.</p>
  <pre><code>[FunctionName(&quot;ObjectRead&quot;)]
  [OpenApiOperation(operationId: &quot;Run&quot;, tags: new[] { &quot;name&quot; })]
  [OpenApiSecurity(&quot;function_key&quot;, SecuritySchemeType.ApiKey, Name = &quot;code&quot;, In = OpenApiSecurityLocationType.Header)]
  [OpenApiRequestBody(&quot;application/json&quot;, typeof(FileDetails))]
  [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: &quot;application/json&quot;, bodyType: typeof(string), Description = &quot;The OK response&quot;)]
  public async Task&lt;IActionResult&gt; Run(
      [HttpTrigger(AuthorizationLevel.Function, &quot;post&quot;, Route = null)] HttpRequest req)
  {
      _logger.LogInformation($&quot;ObjectRead function triggered at {DateTime.UtcNow.ToString(&quot;O&quot;)}.&quot;);
  
      var requestBody = await new StreamReader(req.Body).ReadToEndAsync().ConfigureAwait(false);
      var data = JsonConvert.DeserializeObject&lt;FileDetails&gt;(requestBody);
      var responseMessage = await _objectReadService.ReadAsync(data.FileName, data.FilePath).ConfigureAwait(false);
  
      _logger.LogInformation($&quot;ObjectRead function completed at {DateTime.UtcNow.ToString(&quot;O&quot;)}.&quot;);
      return responseMessage.Length != 0 ? new FileStreamResult(responseMessage, &quot;application/octet-stream&quot;) { FileDownloadName = data.FileName} : new NotFoundObjectResult(&quot;Unable to retrieve the file or File not found.&quot;);
  }
  </code></pre>
  <p>Above code snippet 3rd line I have mentioned the key as header</p>
  <p>Even why its not working in swagger and in url why the code still shows as query string</p>