Download MetaTrader 5

WebRequest - Error when hitting a local url

To add comments, please log in or register
gr101
196
gr101 2015.10.22 20:43 

Hi,

I"m trying to fetch a local url on my machine (http://localhost:52957). The code below is from the following url (https://www.mql5.com/en/docs/common/webrequest).

I am able to browse to http://localhost:52957 with a web browser.

I keep getting the following error:

5200

ERR_WEBREQUEST_INVALID_ADDRESS

Invalid URL


I have added that url above (the localhost one) to the allowed WebRequest pages.

Any idea how to fix this?

Thanks

Code:

string cookie=NULL,headers;

   char post[],result[];
   int res;
//--- to enable access to the server, you should add URL "https://www.google.com/finance"
//--- in the list of allowed URLs (Main Menu->Tools->Options, tab "Expert Advisors"):
   string google_url= "http://localhost:52957"; // "http://www.microsoft.com"; // "http://localhost:52957/"; // "https://www.google.com/finance";
//--- Reset the last error code
   ResetLastError();
//--- Loading a html page from Google Finance
   int timeout=5000; //--- Timeout below 1000 (1 sec.) is not enough for slow Internet connection
   res=WebRequest("GET",google_url,cookie,NULL,timeout,post,0,result,headers);
Google Finance: Stock market quotes, news, currency conversions & more
  • www.google.com
Get real-time stock quotes & charts, financial news, currency conversions, or track your portfolio with Google Finance.
InvestSoft
8705
Janusz Trojca 2015.10.22 21:50  

I have found in WebRequest function description:

Server port is automatically selected on the basis of the specified protocol - 80 for "http://" and 443 for "https://".

You can try to use functions InternetOpenUrlW from wininet.dll library. It shouldn't be a problem to find on forum working example. 

gr101
196
gr101 2015.10.22 21:58  

Ha!

That was it... thank you thank you thank you :))

InvestSoft
8705
Janusz Trojca 2015.10.22 22:25  
no problem :)
To add comments, please log in or register