Setting a header/content type with HTTPPostAsync

Hi,

I’m trying to send some JSON data to an external web server

Example json:

{"status": {"current_time": "now"}}

Example .mls code

VAR

  build_response: IPersistentObject;
  build_response2: IPersistentObject;
  message: string;

BEGIN

     build_response := Factory.CreatePersistentObject;
     build_response2 := Factory.CreatePersistentObject;

     build_response2.SetString('current_time', 'now');
     build_response.SetObject('status', build_response2);

     message := build_response.AsJSon(true, true);

     HTTPPostAsync('http://localhost:1885/mypage/section/playlist' , message);
END.

The message arrives with a content type:

“application/x-www-form-urlencoded” instead of the required “application/json”

This causes the receiving framework(s) to try to parse the body.

This breaks things.

I lose the body and need to recreate the json from a form dictionary. This dictionary does not allow duplicates, so duplicate fields and field delimiters are lost.

Is there a way to set the header correctly, or do I need to patch the receiving framework to accept this?

You cannot tweak any parameters at this time; but it might be possible to use the IRESTClient interface in this particular situation.

var 
  client: IRESTClient;

begin
  // create build_response as above

  client := CreateRESTClientWithCredentials('http://localhost:1885', '', '');
  client.PostJSON('/mypage/section/playlist', build_response);
end.

Thanks, that works, that means for me this is solved.

This is the header I now get:

Connection: keep-alive
Content-Type: application/json
Content-Length: 4047
Host: 127.0.0.1:1885
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: identity
User-Agent: Mozilla/5.0 (compatible; mAirList/6.1.10.3944)