1 year ago
#329234
rerat
Getting error when sending POST request to server using MQL4
I am trying to post data using an MQL4 script to a local server on the same network and I am getting errors.
Here is the code:
#import "Wininet.dll"
int InternetOpenW(string, int, string, string, int);
int InternetConnectW(int, string, int, string, string, int, int, int);
int InternetOpenUrlW(int, string, string, int, int, int);
int InternetReadFile(int, string, int, int& OneInt[]);
int InternetCloseHandle(int);
int HttpOpenRequestW(int, string, string, string, string, string& AcceptTypes[], int, int);
bool HttpSendRequestW(int, string, int, string, int);
#import
#import "kernel32.dll"
int GetLastError(void);
#import
int OnInit()
{
string headers = "Content-Type: application/x-www-form-urlencoded";
string data = "test=test";
string acceptTypes[1] = {"*/*"};
int HttpOpen = InternetOpenW("HTTP_Client_Sample", 1, "", "", 0);
int HttpConnect = InternetConnectW(HttpOpen,
"http://192.168.0.201/api", 7777, "", "", 3, 0, 1);
int HttpRequest = HttpOpenRequestW(HttpConnect, "POST", "/index.php", "HTTP/1.1", "",
acceptTypes, 0, 1);
bool result = HttpSendRequestW(HttpRequest, headers, StringLen(headers), data,
StringLen(data));
Alert ("Last MSDN Error =: ", kernel32::GetLastError());
int read[1]; // not used
Alert("This is the POST result: ", result);
if (HttpOpen > 0)
InternetCloseHandle(HttpOpen);
if (HttpRequest > 0)
InternetCloseHandle(HttpRequest);
Alert("DONE");
}
So the MSDN error is 6. Tried to look that up, but came up with nothing. The result is false, so obviously not working.
Any suggestions would be great.
mql4
0 Answers
Your Answer