Simple POST/GET HttpRequest with mql4 - page 3

 
coolex:

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


It was just a hint, not a guide.
 
what MT4 build are you using ?
 

I use Build 610.

 
coolex:

I use Build 610.


I'm also trying to use the code and it gives me "Access Violation" errors with build 610.

As per this post (https://www.mql5.com/en/articles/276) users on MQL5 are getting the same problem ....

B&KR.

 

i'm using B617 and works just fine i'm going to install B610 to check it out

please be patient ;-)
 

ok here we go (fixed for B610)

#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, char& AcceptTypes[], int, int);
   bool HttpSendRequestW(int, string, int, string, int);
#import
#import "kernel32.dll"
int GetLastError(void);
#import


   string headers = "Content-Type: application/x-www-form-urlencoded";
   string data = "";
   string Types = "";
   char acceptTypes[];
   StringToCharArray(Types, acceptTypes);
   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);
 

and this example works to

#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, int, int);
   bool HttpSendRequestW(int, string, int, string, int);
#import
#import "kernel32.dll"
int GetLastError(void);
#import


   string headers = "Content-Type: application/x-www-form-urlencoded";
   string data = "";
   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", "", "", data, 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);
 

GREAT! Both example work. So much thank you.

 
sergiensergien:

As per this post (https://www.mql5.com/en/articles/276) users on MQL5 are getting the same problem ....



it's a different reason why they getting the error but here is MQL4 so...
 
coolex:

GREAT! Both example work. So much thank you.


i think you should use the right parameters (or all of them)

#define INTERNET_FLAG_PRAGMA_NOCACHE   0x00000100  // no caching of page
#define INTERNET_FLAG_KEEP_CONNECTION  0x00400000  // keep connection
#define INTERNET_FLAG_RELOAD           0x80000000  // get page from server when calling it

int HttpRequest = HttpOpenRequestW(HttpConnect, "GET", "ff_calendar_thisweek.xml", "", "", 0, 
INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_PRAGMA_NOCACHE, 0);   

Reason: