WebRequest

 

Next and last question and for this Forex Game i'm building ;-) And it's going to be fun and might even be profitable for the players!

Can anyone give an example of how to send some data with the webrequest?

The data I want to send is a simple comma seperated list with doubles: 1283762323234, 1.23244, 0.87357 etc.

Thanks en best regards,

Jeex

 
Well you know the the command, you have the mql4- reference, why don't you try this example first?
 

Maybe, because it did not do the job properly?

The example does not send data, it receives data. As one can read in my question, i want to send some data with GET or POST.

 

1) May be it isn't meant for that and "not implemented yet".

2) Please seek your headline on this forum - there you get more information and an idea for what it is meant

3) Ask the Service Desk.

4) May be the ftp-option or the email might do what you want?

 
jeex:

The example does not send data, it receives data. As one can read in my question, i want to send some data with GET or POST.

The example does send data. In a GET request, the data being sent is simply the URL. If you want to "send data" in a GET request then you simply modify the URL in the example. For example, the following uses a GET request to Google Finance in order to get a stock quote for GOOG:

string headers;
char post[], result[];
int res = WebRequest("GET", "http://www.google.com/finance/info?q=NASDAQ%3aGOOG", "", NULL, 10000, post, ArraySize(post), result, headers);
Print("Status code: " , res, ", error: ", GetLastError());
Print("Server response: ", CharArrayToString(result));

Sending data through a POST simply consists of (a) changing the method from GET to POST and (b) filling in the post[] array. For example, the following creates a JPY-denominated account in Oanda's sandbox development environment:

string headers;
char post[], result[];
StringToCharArray("currency=JPY", post, 0, 12); // Must specify string length; otherwise array has terminating null character in it
int res = WebRequest("POST", "http://api-sandbox.oanda.com/v1/accounts", "", NULL, 10000, post, ArraySize(post), result, headers);
Print("Status code: " , res, ", error: ", GetLastError());
Print("Server response: ", CharArrayToString(result));

How you process POST data then depends on your server environment. The main limitation of WebRequest is that you can't set the request headers, and therefore you can't specify things like Content-Type:application/x-www-form-urlencoded 

One other note: it looks as though WebRequest() ignores the data_size parameter and always sends the the whole of the data[] array

 

Thanks jjc,

That is something I can work with. In fact: it works:

...

char post[];

StringToCharArray( "rates=EURUSD:1.25234,EURGBP:0.78451,GBPUSD:1.58743", post );

res = WebRequest( "POST", url, koekje, NULL, tijd, post, 0, result, headers );

...

It was the char[] that was a bit confusing.

 
...

char post[];

StringToCharArray( "rates=EURUSD:1.25234,EURGBP:0.78451,GBPUSD:1.58743", post );

res = WebRequest( "POST", url, koekje, NULL, tijd, post, 0, result, headers );

...

Can anyone tell me what the string is like if I want to post the following to my webpage :

$_POST['EURUSD']  == 1.25234; $_POST['EURGBP'] == 0.78451;

what is the format of the string to be posted to a webpage? Is it like field name:field value,field name:field value,field name:field value, ... ?  

 
StringToCharArray( "EURUSD=1.25234&EURGBP=0.78451", post );
 

I have seen the sample code for uploading image to mql5 community wall. 
Did anyone share an idea (or better: a sample code) of how to upload image to privet server?

No authentication and cookies handling needed - just upload an image using POST/GET protocol.

Thank you 

Reason: