WebRequest always return code -1

 

Hi guys,

I am facing wired problem when I am trying to use WebRequest() function on Windows.


Here is the simplest code which could be written:

void OnStart()
{
   string url = "http://server.com";
   string headers = "application/json";
   int timeout = 5000;
   char post[],result[];
   string result_header;
   int res;
   
   string message = "this is a test";
   StringToCharArray(message,post,0,StringLen(message));
   res=WebRequest("POST", url, headers, timeout, post, result, result_header);
   Print(res);
   if (res == -1) {
      Print("Error in WebRequest. Error code  =",GetLastError());
   }
}

Of course I've added the https://google.com to options->ExpertAdvisors tab.

I am running Wine on Ubuntu on which I am running the Metatrader4. On this instance I got res=200 which is quite ok


The problem is when I try to install the following Script on a Windows 8.1. On that Windows I have internet access (I can load any page from a browser) and of course the address is in the options->expert advisors

MetaTraders are the same versions, but when I install it and run it, I always got res=-1 and the last error is 5203.


Is it possible WebRequest to require some permissions from Windows, or is it using something like Curl-like app which is missing and it couldn't execute the web request, or even some Service Pack which is not installed? I am more linux than Windows user and I didn't install that Windows (it's a friend of mine), so not sure if everything is correctly there.

Also I tried to install Metatrader on a VirtualMachine (VirtualBox) Win8.1 and I got the same error, so it let me think it could be some Windows related.


Does anyone experienced the same problem?

Any help is much appreciated

 
nchankov:

Hi guys,

I am facing wired problem when I am trying to use WebRequest() function on Windows.


Here is the simplest code which could be written:

Of course I've added the https://google.com to options->ExpertAdvisors tab.

I am running Wine on Ubuntu on which I am running the Metatrader4. On this instance I got res=200 which is quite ok


The problem is when I try to install the following Script on a Windows 8.1. On that Windows I have internet access (I can load any page from a browser) and of course the address is in the options->expert advisors

MetaTraders are the same versions, but when I install it and run it, I always got res=-1 and the last error is 5203.


Is it possible WebRequest to require some permissions from Windows, or is it using something like Curl-like app which is missing and it couldn't execute the web request, or even some Service Pack which is not installed? I am more linux than Windows user and I didn't install that Windows (it's a friend of mine), so not sure if everything is correctly there.

Also I tried to install Metatrader on a VirtualMachine (VirtualBox) Win8.1 and I got the same error, so it let me think it could be some Windows related.


Does anyone experienced the same problem?

Any help is much appreciated


you spoke about google.com but string url = "http://server.com"; ???

 

Well, both were used as example. I wrote google, then switched the code to server.com as to show it's any server.

I came to the conclusion that it's an issue with the Windows, but I can't find any resource pointing to a solution or what cause it

 
nchankov:

Well, both were used as example. I wrote google, then switched the code to server.com as to show it's any server.

I came to the conclusion that it's an issue with the Windows, but I can't find any resource pointing to a solution or what cause it


did you try all different headers : I face another problem with webrequest and the solution was headers :

string headers = "User-Agent: Mozilla/4.0\r\n"; or "User-Agent: Mozilla/5.0\r\n";  there's plenty of possibility !

 
In MetaTrader -> Menu -> Tools -> Options -> Tab: Expert Advisors: "Allow WebRequests for listed URL" -> Add the URL where your request goes to (e.g. http://some-remote-server.com or http://192.168.0.4).
 
Marcel Fitzner #:
In MetaTrader -> Menu -> Tools -> Options -> Tab: Expert Advisors: "Allow WebRequests for listed URL" -> Add the URL where your request goes to (e.g. http://some-remote-server.com or http://192.168.0.4).
Thank you very much