Content-Type in SOAP request. Different behaviour On-prem vs. BC

Lars_WestmanLars_Westman Member Posts: 116
edited 2018-09-05 in NAV Three Tier
I have AL code running fine on-prem, but when I deploy in BC running on Docker the request header seems to be created differently. The result is an error 415 "Unsupported Media Type"

This is parts of the AL code:
var
    MyHttpClient: HttpClient;
    RequestMessage: HttpRequestMessage;
    ResponseMessage: HttpResponseMessage;
    Headers: HttpHeaders;
    Content: HttpContent;
    XMLRequest: text;
    XML_text: text;
begin
    RequestMessage.SetRequestUri(URL);
    RequestMessage.Method('POST');
    Content.GetHeaders(Headers);
    Headers.Remove('Content-Type');
    Headers.Add('Content-Type', 'text/xml;charset=utf-8');
    XmlDoc.WriteTo(XML_text);
    Content.WriteFrom(XML_text);
    RequestMessage.Content := Content;
    MyHTTPClient.send(RequestMessage, ResponseMessage);

When running on-prem the Headers.Remove and Headers.Add needs to be there, otherwise I get error 415 also on-prem.

The same code seem to behave differently in BC. One problem I have is that I haven't figured out how to sniff the http-traffic from the Docker container. Normally I use Fiddler for that, but that's not possible here. Maybe if I succeeeded in configuring my host as a proxy for the container, but that doesn't seem trivial.

Is there any idieas on this out there?

Answers

  • Lars_WestmanLars_Westman Member Posts: 116
    edited 2018-09-05
    I was able to inspect the traffic and it looks like Headers.Remove and Headers.Add doesn't work the same way in the two environments.

    This changes Content-Type from "text/plain; charset=utf-8" to "text/xml;charset=utf-8" when running locally in NAV2018 but not in BC
    Headers.Remove('Content-Type');
    Headers.Add('Content-Type', 'text/xml;charset=utf-8');
    

    Reported here: https://github.com/Microsoft/AL/issues/3579
Sign In or Register to comment.