Discussion of article "Using WinInet in MQL5. Part 2: POST Requests and Files"

 

New article Using WinInet in MQL5. Part 2: POST Requests and Files is published:

In this article, we continue studying the principles of working with Internet using HTTP requests and exchange of information with server. It describes new functions of the CMqlNet class, methods of sending information from forms and sending of files using POST requests as well as authorization on websites under your login using Cookies.

Author: Alex Sergeev

 

Hi Alex,

Good article - I have a request for 'Part 3': XML-RPC client communication (and server if possible).

Cheerz 

 

When executing the following statement, the system crashes, how this should be resolved? 

hConnect=InternetConnectW(hSession, aHost, aPort, aUser, aPass, aService, 0, 0);  

Error: Access violation read to 0x0000000000001F94 in '......ex5'

 

 

 

 

There is a little bug on line 161. That line should be:

else StringToCharArray(req.stData, data, 0, StringLen(req.stData));

that's because terminal 0 is copied to the array and HttpSendRequestW sends the terminal 0 (like an extra character) to the last post var value. For example if your data is:

var1=value1&var2=value2

You will get in your web page var1 associated to value1, and var2 associated to value2\0.

This is a great article. Thanks for sharing it.


Regards

 
after the last MT5 upgrade the wininet cant be used, ir generates an access violation error. Any suggestions to overcome this error? solutions? I've been trying without success.
 
Access violation error was solved but POST requests are not working now. Apparently the data in an uchar array is not correctly sent to the dll function.
 
mundoforex:

Access violation error was solved but POST requests are not working now. Apparently the data in an uchar array is not correctly sent to the dll function.
I'm still having access violation errors after some time.
 

Why nobody cares this problem??
 
mundoforex:

Why nobody cares this problem??
I'm with you... I'm desperately waiting for a solution but no one answers. I thought the last update was going to solve the problem as the admins told me, but after the update the never answered me again :(
 

I also had some Access Violation error with this object class. The problem was in using '0' as a NULL pointer in call of HttpOpenRequestW function. Try to replace the call

---   hRequest=HttpOpenRequestW(hConnect, req.stVerb, req.stObject, Vers, nill, 0, INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_PRAGMA_NOCACHE, 0); 

with a call:

+++   hRequest=HttpOpenRequestW(hConnect, req.stVerb, req.stObject, Vers, NULL, NULL , INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_PRAGMA_NOCACHE, 0); 


It is funny, that improper use of NULL pointer is even explicitly mentioned as a crash reason in MSDN documentation:

Failing to properly terminate the array with a NULL pointer will cause a crash.
HttpOpenRequest function (Windows)
  • msdn.microsoft.com
Creates an HTTP request handle. Syntax Parameters hConnect [in] lpszVerb [in] A pointer to a null-terminated string that contains the HTTP verb to use in the request. If this parameter is NULL, the function uses GET as the HTTP verb. lpszObjectName [in] A pointer to a null-terminated string that contains the name of the target object of the...
 

Thanks anyway for the great library. 
I finally managed to POST data through wininet, so let me also contribute something here:

for access violation,
1. Changing "nill" to NULL does not help
2. Changing "nill" to 0 does not help

what I did is actually changed the following:

--- string nill = "";
+++ string nill = "\0";

and everything will be fine after that. Enjoy :)

Reason: