HTTP Requests from Business Central – Expect 100-Continue

I doubt this will have a very wide audience who need this, but I wanted to write it up for the future sanity of somebody.

I was creating a Business Central Extension that needed to call a POST API call to a very very picky API endpoint – if there were unexpected headers, failure.

Upset looking child, covering his mouth, looking scared of a piece of broccoli on a fork, being presented like a parent feeding the child. Child captioned "Picky API". Broccoli captioned "Extra .NET Headers"
Honestly, I’m annoyed with everyone involved here.

So, I was frustrated to realize that Business Central was automagically adding a new HttpHeader on sending the request, “Expect” with a value of “100-continue”. Digging into things, this header is automatically added during the send process, so no level of trying to change the HTTP Headers was going to help me.

Thanks to this ancient post from 2004 about HttpWebRequests with .NET, I at least had the info above to work with. Deep in the comments was a pointer to the magic I needed.

In the Microsoft.Dynamics.NAV.Server.exe.config file, we can turn off this ‘helper’. In the system.net section that looks roughly like so:

  <system.net>
    <settings>
      <httpListener unescapeRequestUrl="false" />
    </settings>
  </system.net>

Update that to include a setting change to the servicePointManager:

  <system.net>
    <settings>
      <httpListener unescapeRequestUrl="false" />
      <servicePointManager expect100Continue="false" />
    </settings>
  </system.net>

Restart the service tier, and voila! No more ‘helping’. Picky API, in my case, was finally satisfied.

Leave a Reply

Your email address will not be published. Required fields are marked *