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 Terminal 4 webrequest.mq4
中的文件发送到可以放弃的节点此站点部分。
MT4>>的NodeJS
??? POST [] ??? (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 :(得分:0)
请注意细节:
MQL4
部分MQL4.56789
副本/粘贴代码失败 作为第一个迹象,网络上静态存在的 MetaTrader Terminal 4
代码库并不反映MQL4
语言的蠕动语法变化。最近MQL4
已接近MQL5
(推理此帖子之外,如果有兴趣,请查看有关新建< - em> 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
相关的任何其他任务,而不是使用 localhost
- 来自的服务Help
,在网络上搜索&#34; help&#34; ,由于上述原因,大多数都会成为未经编辑的复制/粘贴尝试的误导性来源
IDE
http语法结构应符合POST
,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
部分应解密 node.js
-url编码的http消息中传递的参数。
工作完成了。
欢迎来到 POST