Web Request in mql5

Web Request in mql5

Manage alerts

Loading saved threads...

Kaweng Mancha · External communityPost link
External question — Stack Overflow Stack Exchange Author: Kaweng Mancha Original post: https://stackoverflow.com/questions/76351911 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. #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)); } } This code is expected to fetch user details on their mt5 accounts and send to my servrer which is already set up. But on this line: 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 ); I get the error: 'WebRequest' - no one of the overloads can be applied to the function call could be one of 2 function(s) built-in: int WebRequest(const string,const string,const string,const string,int,const char&[],int,char&[],string&) built-in: int WebRequest(const string,const string,const string,int,const char&[],char&[],string&) Please help me out here
Quote
Report
acfrai · External communityPost link
External answer — Stack Overflow Stack Exchange Author: acfrai Original post: https://stackoverflow.com/a/79176185 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. It's been quite some time, but what it looks like the problem is your last parameter, you're defining it as char headers[]; while it should be a string like string headers;
Quote
Report
LukiRoth · External communityPost link
External answer — Stack Overflow Stack Exchange Author: LukiRoth Original post: https://stackoverflow.com/a/79325056 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Both of your header variables should be defined as strings, not as character arrays. Additionally, you need to remove the data length input "ArraySize(postData)" as it's not required in this context. string headerString = "Content-Type: application/x-www-form-urlencoded"; string headers; int res = WebRequest( "POST", // (string) HTTP method URL_create_account, // (string) Request URL headerString, // (string) Request headers timeout, // (int) Request timeout postData, // (char[]) POST data result, // (char[]) Response content headers // (string) Response headers );
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: LukiRoth Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/79325056 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Both of your header variables should be defined as strings, not as character arrays. Additionally, you need to remove the data length input "ArraySize(postData)" as it's not required in this context. string headerString = "Content-Type: application/x-www-form-urlencoded"; string headers; int res = WebRequest( "POST", // (string) HTTP method URL_create_account, // (string) Request URL headerString, // (string) Request headers timeout, // (int) Request timeout postData, // (char[]) POST data result, // (char[]) Response content headers // (string) Response headers );

Cancel quote

Checking account access…