webrequest doesn't contain post data in mql4

 

Hi,

I am struggling to find out what might be wrong with my webrequest and the reason why there is no post data.

      string cookie=NULL, headers;
      char post[], result[];
      string url = "url_to_a_server";
      
      StringToCharArray("some_info", post);
      Print("post: ", CharArrayToString(post));
      
      int res=WebRequest("GET",url,cookie,NULL,500,post,0,result,headers);

The above snippet of code works in mql5 and I get post data on the server side. However the same request in mql4 sends no post data to the server.

I have added the URL in the listed URLs and I can see that there is a request coming from mt4 however the payload is just an empty b''

Any ideas?

 
roniko1994: The above snippet of code works in mql5 and I get post data on the server side. However the same request in mql4 sends no post data to the server.

I would think that the code would also not work on MT5. Your data_size is zero in the call, so no data should be sent.

 
William Roeder:

I would think that the code would also not work on MT5. Your data_size is zero in the call, so no data should be sent.

Interestingly enough it works in MT5 as I copied it over from one of my applications that is up an running.

I am still puzzled as to why it doesn't work. Even in the documentation they use 0 as data_size when doing a post request

Ps. Changing the data size doesn't help in any way

https://docs.mql4.com/common/webrequest

WebRequest - Common Functions - MQL4 Reference
WebRequest - Common Functions - MQL4 Reference
  • docs.mql4.com
To use the WebRequest() function, add the addresses of the required servers in the list of allowed URLs in the "Expert Advisors" tab of the "Options" window. Server port is automatically selected on the basis of the specified protocol - 80 for "http://" and 443 for "https://". The WebRequest() function is synchronous, which means its breaks the...
 
roniko1994:

Hi,

I am struggling to find out what might be wrong with my webrequest and the reason why there is no post data.

The above snippet of code works in mql5 and I get post data on the server side. However the same request in mql4 sends no post data to the server.

I have added the URL in the listed URLs and I can see that there is a request coming from mt4 however the payload is just an empty b''

Any ideas?

use StringLength
StringToCharArray("some_info", post,0,StringLen("some_info"));

will work on MQL4 , because I think there is glitch in mql4 as it uses by default value "WHOLE_ARRAY"  I don't know why  it doesn't work with WebRequest correctly , maybe because it results in one more char than actual length of string , anyways I use it like that and it works. when I use the defulalt values of StringToChar it doesn't .

Also use the second version of the WebRequest which doesn't use data size in it 

Btw why you don't just add the data that you want to pass to the url as you are using "GET" method ?

Documentation on MQL5: String Functions / StringLen
Documentation on MQL5: String Functions / StringLen
  • www.mql5.com
String Functions / StringLen - Reference on algorithmic/automated trading language for MetaTrader 5
 
Kareem Abdelhakim:
use StringLength

will work on MQL4 , because I think there is glitch in mql4 as it uses by default value "WHOLE_ARRAY"  I don't know why  it doesn't work with WebRequest correctly , maybe because it results in one more char than actual length of string , anyways I use it like that and it works. when I use the defulalt values of StringToChar it doesn't .

Also use the second version of the WebRequest which doesn't use data size in it 

Btw why you don't just add the data that you want to pass to the url as you are using "GET" method ?

"Btw why you don't just add the data that you want to pass to the url as you are using "GET" method"

Yes, this is what I did and it worked. I guess this approach is better than passing arrays. 

Thanks for the advice!

 
roniko1994:

"Btw why you don't just add the data that you want to pass to the url as you are using "GET" method"

Yes, this is what I did and it worked. I guess this approach is better than passing arrays. 

Thanks for the advice!

Actually yes data are meant more for JSON data with POST method , if it's get then it's easier to pass parameter to the url directly
Reason: