Download MetaTrader 5

Understanding WebRequest Post HTTP

To add comments, please log in or register
Write your articles using our editor. It is convenient!
qrmarketing
6
qrmarketing 2015.03.21 14:15 

I am just trying to do a hello world programme with WebRequest and finding it a bit difficult. Send a post request to a php page and return the response. I have searched the forums for examples and there is little. The one MT uses does not even compile. Not sure why they can't just give a simple example. Anyway. Any help would be appreciated, as well for others. I get the feeling I am not the only one, judging by comments on forum posts. 

Here is what I have, the results of this is that it does go to the URL and executes the PHP, the issue is that the $_post yields nothing. I do see in the header the content length change when I adjust the input - just no data. There must be a secret to this data input field of WebRequest. I tried to play with refer, etc....it does nothing. Simple defaults seem to work the same.

EA script. 

int init()

{

string headers;

char data[], result[];

string str = "data=value"; // post data variables to send

StringToCharArray(str,data);

string b = CharArrayToString(data);

Print("Test:",b); // just test if good ... it is.

WebRequest("POST","http://xyz.com/xyz.php",NULL,NULL,3000,data,ArraySize(data),result,headers); 

Print(CharArrayToString(result)); // see the results and it retuns "Results:" No posted data.

The PHP: xyz.php 

<?php

$data = $_POST["data"];

echo "Results:" . $data;

?>

To add comments, please log in or register