如何从MQL4向NodeJS发送POST消息
How to send a POST message from MQL4 to NodeJS?
webrequest.mq4
#property copyright "Copyright 2013, apla"
#property link "-"
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
// WebRequest
string cookie = NULL;
string headers = "Content-Type: application/x-www-form-urlencoded";
int res;
string url = "localhost:8080"; // url = localhost:8080
char post[], result[];
string signal = "account=" + AccountNumber() + "&balance=" + AccountBalance() + "&equity=" + AccountEquity();
StringToCharArray( signal, post );
Print( signal );
int timeout = 5000; // 5 sec
res = WebRequest( "POST",
url,
cookie,
NULL,
timeout,
post,
ArraySize( post ),
result,
headers
);
Print( "Status code: " , res, ", error: ", GetLastError() );
//----
return(0);
}
//+------------------------------------------------------------------+
我想把一个文件从MetaTrader终端4 webrequest.mq4
发送到一个节点这个网站部分,但可以放弃。
MT4>>Nodejs
张贴[]???(JavaScript节点)账户、余额、权益
如何将file.php转换为nodejs
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "account ".$_POST['account']."'n";
fwrite($myfile, $txt);
$txt = "balance ".$_POST['balance']."'n";
fwrite($myfile, $txt);
$txt = "equity ".$_POST['equity']."'n";
fwrite($myfile, $txt);
fclose($myfile);
?>
为此,我不知道如何获得POST。
writeFile.js
var http = require('http'); var fs = require('fs');
fs.writeFile("file.txt",??? POST[] ???, function(err,data) {
if (err) throw err;
console.log('The file was saved!');
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('OK');
}).listen(8080);
console.log('Server running at http://localhost:8080/'); });
请注意细节:
步骤0:
MQL4
部分
应遵循最近的新建-MQL4.56789
复制/粘贴代码失败
作为这一点的第一个迹象,网络上静态存在的MetaTrader Terminal 4
代码库并没有反映出MQL4
语言的语法变化。最近,MQL4
已经向MQL5
靠拢(推理不在本文范围内,如果感兴趣,请查看关于New-MQL4.56789
的其他帖子)。
int start(){...} // cannot be used anymore,
// neither for EXPERT_ADVISOR
// nor for SCRIPT
最近的#property strict
编译模式强制使用:
void OnTick(){ ...} // for EXPERT_ADVISOR type of MQL4-code
void OnStart(){ ...} // for SCRIPT type of MQL4-code
int OnCalculate(...){ ...} // for CUSTOM_INDICATOR type of MQL4-code,
// while,
// CUSTOM_INDICATOR has explicitly
// FORBIDDEN any attempt
// call to a WebRequest( ... ) et al
也就是说,代码的MQL4
部分应在其主体结构中进行修改,以反映这些事实。
对于任何与MQL4
相关的进一步任务,而不是使用IDE
中安装的localhost
Help
服务,由于上述原因,在web上搜索"帮助"将成为未经编辑的复制/粘贴尝试的误导来源。
步骤1:
POST
http语法构造
应符合RFC 7231
、Section 4.3.3
至少,存储在string signal
中的构造文本应该如下所示:
User-Agent: aplaHTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 54
account=123456789&balance=1234567.89&equity=1234567.89
步骤2:
Node.js部分
解析接收到的参数以进行任何进一步的后处理
类似地,node.js
部分应解密POST
-url编码的http消息中传递的参数。
工作完成了。
欢迎来到MQL4
相关文章:
- 通过AJAX向同一页面发送POST请求,并使用$_POST获取值
- 如何在cloud9中向server.js发送post请求
- Angular JS `$http`发送POST而不是GET
- 在表单上注入javascript以发送post请求
- 如何在IE CORS中发送POST数据(使用XDomainRequest)
- 通过发送POST参数在ExtJS 4中显示PDF
- 如何从MQL4向NodeJS发送POST消息
- 从python向django发送Post Data
- firebug:如何在firebug控制台中发送POST数据
- 我使用jQuery发布的表单不发送POST变量
- gwt使用本机javascript向远程服务器发送POST请求失败
- 如何通过头中带有自定义参数的RestTemplate发送POST请求
- Javascript没有在Firefox中发送post参数
- 如何使用 AJAX 发送 POST 数据?以及如何在Web API中获取POST数据
- 使用 AJAX JQuery 发送 POST 数据
- 使用 Express.js 在服务器上发送 POST 请求
- 在 ajax post 成功后,如何使用 JQuery .load() 方法发送 POST 请求
- 如何在 Ember 中发送 POST 来代替 PUT 或 DELETE
- SweetAlert:如何在单击“确定”后发送POST请求
- 如何在 ajax 中发送 POST 数据