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