Bug in Web

 

I'm using the WebRequest code below to generate HTTP POST request:

====================================================================== 

   string cookie=NULL, headers;

   char post[], result[];

   int res;

   string url="http://postcatcher.in/catchers/5530766d71eeb8030000253c";

   ResetLastError();

   int timeout=5000;

   string str = "payload=%7B%22text%22%3A+%22This+is+another+line+of+text.%22%7D";

   StringToCharArray(str,post);

   res=WebRequest("POST",url,cookie,NULL,timeout,post,ArraySize(post),result,headers);

 =============================================================

 The result, as seen on the catcher side is: '{"text": "This is another line of text."}' . "\0" . '' 

Where the correct outcome should be: {"text": "This is another line of text."} 

We see additional characters '. "\0" . " in the sent string which is rejected at the destiny failing to be recognized as a JSON message.

In my opinion, this is clearly an MQL5 bug. Can someone comment or help? 

 

I could be way off the mark here but have you tried changing the encoding to UTF8 ? So something like this in the String to Array call before the web request:

 

StringToCharArray(str,post,0,WHOLE_ARRAY,CP_UTF8);
 

Thanks for your response, Filter. Problem solved!

We need to explicitly define the string length when converting to CharArray. Otherwise it appends a NULL character. There's no need to change encoding to UTF8 however.

StringToCharArray(str,post,0,StringLen(str)); 

 
Good stuff, thanks for reporting back mate.

Cheers
Reason: