title: Optional parameters in HttpPost MVC marked as required?
body: <p>In my C# code, I have a method in my Microsoft.AspNetCore.Mvc.ApiController that gets values. However, if I call the GetThingsAsync method without having the Origin header set in the POST call, I get a 400 BadRequest error.</p>
  <pre><code>        [HttpPost]
          [Route(&quot;route&quot;)]
          public async Task&lt;IActionResult&gt; GetThingsAsync(
              [FromBody] SomeRequest someRequest,
              [FromHeader(Name = &quot;Origin&quot;)] string origin = &quot;Unknown&quot;)
          {
              // Code goes here
          }
  </code></pre>
  <p>The error I get is like this:</p>
  <pre><code>{
      &quot;type&quot;: &quot;https://tools.ietf.org/html/rfc7231#section-6.5.1&quot;,
      &quot;title&quot;: &quot;One or more validation errors occurred.&quot;,
      &quot;status&quot;: 400,
      &quot;traceId&quot;: &quot;REDACTED&quot;,
      &quot;errors&quot;:
      {
          &quot;Origin&quot;:
          [
              &quot;The origin field is required.&quot;
          ]
      }
  }
  </code></pre>
  <p>Now, I assumed the code I'm writing should have a default value of Unknown if Origin isn't set. However, the origin value either isn't set properly, or the validation might be too zealous in some way. I'd like to know why I am getting an error when running this code without having the Origin header set in the request.</p>
  <p>I understand that this problem can be fixed by adding a ? to the string argument like so:</p>
  <pre><code>        [HttpPost]
          [Route(&quot;route&quot;)]
          public async Task&lt;IActionResult&gt; GetThingsAsync(
              [FromBody] SomeRequest someRequest,
              [FromHeader(Name = &quot;Origin&quot;)] string? origin = &quot;Unknown&quot;)
          {
              // Code goes here
          }
  </code></pre>
  <p>That being said, I want to know why this header is required even when it has a default value. Is it being set to null?</p>