2

由于我的困惑和菜鸟,我的另外两个问题(这里这里)没有很好地解决;我将有一个最后的 bash 来澄清我的问题。

我需要从我的交易终端发送历史交易和信号。该代码采用 MQL(C 变体)并使用Wininet.dll。我可以使用以下方法将数据发送到我的服务器:

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

我想在我的站点上使用insert.php脚本来读取 [testdata=] 之后的字符串,然后将其插入到我的数据库中以进行进一步分析。此字符串可能有数千个字符长,这会引起对 URL 长度限制的担忧。

人们提到了 cURL 和 jQuery,但我不明白如何使用上面的代码来模拟 POST 请求,因为数据字符串可能会变得非常大,具体取决于我从贸易日志中选择的日期。

我想尝试以正确的方式做到这一点,但它只是机器相互交谈而没有任何形式,所以这让我感到困惑。

如果我使用这个 cURL 示例,如何将长字符串传递给 $data 变量?

提前致谢。

4

2 回答 2

0

您可以使用 WininetHttpSendRequest完成 POST,同时使用尽可能少的 GET/查询数据来保持 URL 简短。您还将使用HttpOpenRequest. 一些示例 c++ 代码可从另一个stackoverflow 帖子中获得。您可以更改dataPayload以适合您的需要。

于 2014-01-07T23:19:34.137 回答
0

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 :)

于 2014-01-08T15:41:36.547 回答