Simple POST/GET HttpRequest with mql4 - page 2

 

many thanks!

I am running an apache server on my computer and use localhost. That's why I don't get the error message you got but instead I get the error "Access violation read to 0x0000007B in 'Wininet.dll'" i using "HttpOpenRequestW".

Have you tried another url?

 
even with my fixed code ?
 

Yes, even with the fixed code.

This is my 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 = "";
   string acceptTypes[1] = {"*/*"};

   int HttpOpen = InternetOpenW("HTTP_Client_Sample", 1, "", "", 0);  
   int HttpConnect = InternetConnectW(HttpOpen, "http://localhost/tradex", 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
   Print("This is the POST result: ", result);
   if (HttpOpen > 0)
   InternetCloseHandle(HttpOpen);
   if (HttpRequest > 0)
   InternetCloseHandle(HttpRequest);
   
   return;
}

Interesting is that if I change "HttpOpenRequestW" to "HttpOpenRequestA" I receive also the error 12005.

 
so like i said before the code works fine but there is a problem with URL
 

Well, I don't know whether "HttpOpenRequestW" or "HttpOpenRequestA" is correct. Now I use "HttpOpenRequestA" otherwise I have the error message "Access violation read to 0x0000007B in 'Wininet.dll'".

Regarding URLs I tried so many different other URLs, even the one from your example (changed POST to GET etc.):

   int HttpConnect = InternetConnectW(HttpOpen, "http://www.forexfactory.com", 7777, "", "", 3, 0, 1);
   int HttpRequest = HttpOpenRequestA(HttpConnect, "GET", "/ff_calendar_thisweek.xml", "HTTP/1.1", "", acceptTypes, 0, 1);
 
@qjol: Don't you get the error message "Access violation read to 0x0000007B in 'Wininet.dll'" if you use "HttpOpenRequestW" in the last code?
 

again as i said before something is wrong with the URL (the error codes doesn't lie) and of course i'm using "HttpOpenRequestW" and not "HttpOpenRequestA"

here is a working code (returns true and there is no error):

   string headers = "Content-Type: application/x-www-form-urlencoded";
   string data = "";
   string acceptTypes[1] = {""};

   int HttpOpen = InternetOpenW(" ", 0, " ", "", 0);  
   int HttpConnect = InternetConnectW(HttpOpen, "www.forexfactory.com", 80, "", "", 3, 0, 0);
   int HttpRequest = HttpOpenRequestW(HttpConnect, "GET", "ff_calendar_thisweek.xml", "", "", acceptTypes, 0, 0);   
   bool result = HttpSendRequestW(HttpRequest, headers, StringLen(headers), data, StringLen(data));
   Alert ("Last MSDN Error =: ", kernel32::GetLastError());
   int read[1];
   Print("This is the POST result: ", result);
   InternetCloseHandle(HttpOpen);
   InternetCloseHandle(HttpRequest);
 

I tested the code on other computers and even on other computers I still get the error: "Access violation read to 0x0000007B in 'Wininet.dll'" using "HttpOpenRequestW".

It's getting really disappointing :-(.

 
coolex:

I tested the code on other computers and even on other computers I still get the error: "Access violation read to 0x0000007B in 'Wininet.dll'" using "HttpOpenRequestW".

It's getting really disappointing :-(.


Microsoft declares

_In_  LPCTSTR *lplpszAcceptTypes

for the access parameter. I am not sure if a pointer to the string[] is compatible with it. I would try changing the string[]& to string&.

 

If I do the change I receive the error message "'&' - reference cannot used".