Posts

Gotcha! Using HttpContent in AL

I have been spending some time with Business Central, trying to get familiar with the usage of HttpClient and its related objects. That's when I ran across this little issue. I was trying to put custom content in to a HttpClient post action. Long story short, I ended up with this codeline: myHttpContent . WriteFrom ( myText ) ; And that gave me this error message at runtime: The server cannot service the request because the media type is unsupported. After a bit of searching around, I conclude that something like the following should do the trick: myHttpContent . WriteFrom ( myText ) ; myHttpHeaders . Add ( 'Content-Type' , 'text/xml' ) ; I ran it and got the following run time error: Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects. This was getting unusual! So I bumble around and came up with the following code:

Welcome to my blog.

This blog is my own notes and explanations regarding programming in Microsoft Dynamics NAV and lately also Microsoft Dynamics Business Central. The content here might not be unique or even original, but part of science is to reproduce other peoples results ... or, indeed, fail to do so :) I don't expect this blog to be pulling thousands of views a day or anything fancy like that, as I write this mostly to document how to do stuff, for my own future reference. If anyone else find it useful, then that is just an added bonus. Since I have yet to achieve perfection, please let me know if any errors or even spelling mistakes have made their way in to my posts.