#property copyright "2023, Kaweng Mancha"
#property link "http://www.fostaa.com.ng"
#property version "1.01"
#property strict
#property description "User Account Information Data Collection"
input string URL_create_account = "http://www.website.com/api/create_account.php";
input string URL_update_account = "http://www.website.com/api/update_account.php";
input string username = "user";
input string password = "password";
int OnInit() {
EventSetTimer(1); // 1 minute timer
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason) {
EventKillTimer();
}
void OnTick() {
// Nothing to do on tick
}
void OnTimer() {
string accountName = AccountInfoString(ACCOUNT_NAME);
double accountBalance = AccountInfoDouble(ACCOUNT_BALANCE);
double accountEquity = AccountInfoDouble(ACCOUNT_EQUITY);
string postDataStr = StringFormat(
"username=%s&accountName=%s&accountBalance=%.2f&accountEquity=%.2f",
username, accountName, accountBalance, accountEquity
);
// Convert string to char array
char postData[];
StringToCharArray(postDataStr, postData);
// Define headers
char postHeader[];
string headerString = "Content-Type: application/x-www-form-urlencoded";
StringToCharArray(headerString, postHeader);
int timeout = 5000; // 5 seconds timeout
char result[], headers[];
int res = WebRequest(
"POST", // method
URL_update_account, // URL
postHeader, // headers
timeout, // timeout
postData, // data
ArraySize(postData), // data size
result, // response content
headers // response headers
);
if (res == -1) {
Print("WebRequest failed with error ", GetLastError());
} else {
Print("Server response: ", CharArrayToString(result));
}
}
此代码预计会获取其 mt5 帐户上的用户详细信息,并将其发送到我已设置的服务器。但在这条线上:
int res = WebRequest(
"POST", // method
URL_update_account, // URL
postHeader, // headers
timeout, // timeout
postData, // data
ArraySize(postData), // data size
result, // response content
headers // response headers
);
我收到错误: 'WebRequest' - 没有任何一个重载可以应用于函数调用 可以是 2 个函数之一
请帮帮我
已经有一段时间了,但看起来问题是你的最后一个参数,你将它定义为
char headers[];
而它应该是像 string headers;
这样的字符串