Question

My other two questions didn't go down too well (here and here), due to my confusion and noob-ness; I'll have a final bash to clarify my problem.

I need to send historical trades and signals from my trading terminal. The code is in MQL (C variant) and uses the Wininet.dll. I can send data to my server using this:

string sData, url;
sData = "abc123,etc,etc";
url = "webname.com/PHP/insert.php?testdata="+sData;
int request = InternetOpenUrl (open, url, NULL, 0, 0, 0);

I want to use the insert.php script on my site to read the string that comes after [testdata=] and then insert it into my database for further analysis. This string could be thousands of characters long, which causes concern for URL length limitation.

People have mentioned cURL and jQuery but I don't understand how the above code can be used to simulate a POST request as the data string can get very large depending on the dates I select from my trade journal.

I want to try to do it the correct way but it's just machines talking to each other without any forms, so that's what's confusing me.

If I use this cURL example, how do I pass a long string to the $data variable?

Thanks in advance.

Était-ce utile?

La solution 2

Success :)))))))))))))

I've managed to write to my database with tens of thousands of characters. I had problems connecting because I was using http:// in the domain name, but when i removed it the code worked and I was able to talk to my script.

MQL (C language)

string myData = "testdata=abc123etc...";
string header = "Content-Type: application/x-www-form-urlencoded";
int open = InternetOpen("HTTP_Client_Sample", 0, "", "", 0); 
int connect = InternetConnect(open, "website.com", 80, "", "", 3, 0, 1); 
int request = HttpOpenRequest(connect, "POST", "/PHP/insert.php", NULL, NULL, acceptTypes, 0, 1);
HttpSendRequest(request, header, StringLen(header), myData , StringLen(myData));

PHP

Notice how i'm now able to use $_POST method which has a limitation of:

suhosin.post.max_value_length 1000000

More than enough for my needs. Before, my PHP script used $_GET which can only read 512 chars.

include("connect.php"); //Connect to the database
$data = $_POST['testdata'];
$result = mysql_query("INSERT INTO test (testdata) VALUES ('$data')");
if ($result) echo $data;
else echo "Error ".$mysqli->error;
mysql_close(); 

Thank you for everyone's help, it's greatly appreciated :)

Autres conseils

You can use Wininet's HttpSendRequest to accomplish the POST while keeping the URL short with as little GET/query data as possible. You'll also be using HttpOpenRequest. Some sample c++ code is available from another stackoverflow post. You can change the dataPayload to suit your needs.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top