New article Using WinInet in MQL5. Part 2: POST Requests and Files is published:
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
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.
Why nobody cares this problem??
Why nobody cares this problem??
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.
- msdn.microsoft.com
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 :)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
New article Using WinInet in MQL5. Part 2: POST Requests and Files is published:
Author: Alex Sergeev