Problem with webrequest in MT4

 

Hi everyone, I have this problem: the same Webrequest works in an EA written in MT5 but gives a 403 error in an EA for MT4. This is the code:

   string cookie=NULL,headers;
   char   post[],result[];
   string url = "https://www.google.com";
   int res=WebRequest("GET",url,cookie,NULL,500,post,0,result,headers);
   if(res > 0)
	...
	...
 

What could be the problem ? Thank you

 
Fabio Cresci:
headers);

I guess error 403 is a server side error(forbidden error)... Not related to mql. And your code is running perfectly on my MT4.

 
The same code, launched by an EA on MT5, works, same webrequest.

What differences are there in the MT4 web request compared to the MT5 web request?

There must be something

 
Fabio Cresci:

Hi everyone, I have this problem: the same Webrequest works in an EA written in MT5 but gives a 403 error in an EA for MT4. This is the code:

What could be the problem ? Thank you

A 403 error indicates that the server understood the request, but it refuses to authorize it. In the context of your code, there could be a few reasons why you are getting this.

Some servers, not all,  require a valid User-Agent header to identify the client making the request. In your code, you're not setting any headers, which might cause the server to reject the request. Try setting a User-Agent header to mimic a web browser: like this....

string headers = "User-Agent: Mozilla/5.0";

or

The server might be blocking requests from certain IP addresses or might have rate limits in place. Check if there are any restrictions on accessing the server from your VPS provider's network.

or

If the server requires a secure connection (HTTPS), ensure that your MT4 platform supports SSL/TLS and that there are no issues with the certificate validation.

or

The server might have specific restrictions or security measures in place that prevent access from certain clients or user agents. Check if there are any server-side configurations that could be causing the issue.

or

The server might require cookies or some form of authentication to access the requested resource. Ensure that you handle cookies and any necessary authentication mechanisms correctly in your code.