Help with following code on HTTP post to php

 

This is a piece of code am trying to use to post a set of 13 parameter values from the mql script to a external php script named upload.php

   string headers = "Content-Type: application/x-www-form-urlencoded";
   string data = "{\"ohlcVectors\":{\"ticker\":\"dax\",\"barIntervalSeconds\":300,\"open\":[6844.2998046875," +
      "6847.7998046875]},\"className\":\"MAIndicator\",\"parameters\":{\"periods\":2}}";

string acceptTypes[1] = {"*/*"};

   int HttpOpen = InternetOpenA("HTTP_Client_Sample", 1, NULL, NULL, 0); 
   int HttpConnect = InternetConnectA(HttpOpen, "127.0.0.1", 7777, NULL, NULL, 3, 0, 1);
   int HttpRequest = HttpOpenRequestA(HttpConnect, "POST", "/tradesheet/upload.php", NULL, NULL, acceptTypes, 0, 1);
HttpSendRequestA(HttpRequest, headers, StringLen(headers), data, StringLen(data));

The compiler keeps throwing an error that the "data" is an incompatible type. That data string was picked up from a site when I was searching for ways for mql to send POST params to php. But I need that string data to have my own parameter values but clueless on how to put it in the right format.

I tried searching quite a bit and just cant find anything helpful.

The following is the parameter list that I need to send to upload.php. Can someone please help me arrange in the format that HttpSendRequestA is expecting it ?

string params[13][13];
params[0][0] = "x1";
params[0][1] = "GOD@GMAIL.com";

params[1][0] = "x2";
params[1][1] = 10000;

params[2][0] = "x3";
params[2][1] = 10000;

params[3][0] = "x4";
params[3][1] = "fxpro";

params[4][0] = "x5";
params[4][1] = "usd";

params[5][0] = "x6";
params[5][1] = 10000;

params[6][0] = "x7";
params[6][1] = 5000;

params[7][0] = "x8";
params[7][1] = 10;

params[8][0] = "x9";
params[8][1] = 10;

params[9][0] = "x10";
params[9][1] = "sdfskfms";

params[10][0] = "x11";
params[10][1] = 232;

params[11][0] = "x12";
params[11][1] = 230;

params[12][0] = "x13";
params[12][1] = "fxpro";

Thanks a ton

 
mqltrader2013:

This is a piece of code am trying to use to post a set of 13 parameter values from the mql script to a external php script named upload.php

Please read some other posts before posting . . .

Please edit your post . . .    please use the   SRC   button to post code: How to use the   SRC   button. 

 

HttpSendRequestA expects in POST exactly the same data string as you would create for GET, i.e. param1=1&param2=2

 

Thanks Ovo. Would you be able to put a example for me. 

 Here are the parameters:

x1="fskdjhf@gmail.com" 

x2 = 10000

 

How do we make a HttpSendRequestA string out of this?

 

 RaptorUk: I will take care next time. 

 

Ok, once more.

x1=fskdjhf@gmail.com&x2=10000

 
bool HttpSendRequestA(int, string, int, string, int);
string data1="x1=GOD@GMAIL.com&x2=10000";
   string acceptTypes[1] = {"*/*"};

   int HttpOpen = InternetOpenA("HTTP_Client_Sample", 1, NULL, NULL, 0); 
   int HttpConnect = InternetConnectA(HttpOpen, "127.0.0.1", 7777, NULL, NULL, 3, 0, 1);
   int HttpRequest = HttpOpenRequestA(HttpConnect, "POST", "/tradesheet/upload.php", NULL, NULL, acceptTypes, 0, 1);
   
   HttpSendRequestA(HttpRequest, headers, StringLen(headers), data1, StringLen(data1));

I tried your solution. It gives me an error "data1 incompatible types"

 

I have defined the variable data1 as a string. 

 

Coupld you help please? 

 
mqltrader2013:

I tried your solution. It gives me an error "data1 incompatible types"

This syntax is what I use. Could you specify more precisely, what it means? The compiler, or the terminal at runtime, or your pHp server?
 

'IT' is the mql compiler which comes with the Metatrader. This is the mql code so will be compiled with the mql compiler. 

 
mqltrader2013:

'IT' is the mql compiler which comes with the Metatrader. This is the mql code so will be compiled with the mql compiler. 

 

 

If your compiler cannot compile, then you very probably made a mistake. 

You asked about the wininet.dll call, a format that HttpSendRequestA expects. You got the correct answer. If you like to play with the wininet.dll, you'd better consult some appropriate Microsoft page, it has nothing to do with the MQL.

Reason: