Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 is an object-oriented language?
AED AED
242
AED AED 2015.10.06 22:10 

Hi,

I've searched the forum and checked https://docs.mql4.com/common/webrequest site but couldn't come to a conclusion.

I'm willing to send specific outputs (such as orders, information about ea) to external web page. I do not get any authhorization errors but I'm getting the following kind of errors:

-----------------------------------------

Status code: 404, error: 4000

Server response: <!DOCTYPE html>
<html style="height:100%">
<head><title> 404 Not Found
</title></head>
<body style="color: #444; margin:0;font: normal 14px/20px Arial, Helvetica, sans-serif; height:100%; background-color: #fff;">
<div style="height:auto; min-height:100%; ">     <div style="text-align: center; width:800px; margin-left: -400px; position:absolute; top: 30%; left:50%;">
        <h1 style="margin:0; font-size:150px; line-height:150px; font-weight:bold;">404</h1>
<h
--------------------------------------------

Server response: <html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 12">
<meta name=Originator content="Microsoft Word 12">


----------------------------

I get the errors because (I guess) the "data" format is not prepared for the web page. I do not know how to prepare the string for the url;

Are there any other examples or documentation how to put a new line to existing htm file or creating a new one?

I would appreciate if someone could guide me.

Thanks



      int res;
      char data[];
      string headers;
      char result[];
      string login="user";
      string password="pass";
      string str="Login="+login+"&Password="+password;
         
      ArrayResize(data,StringToCharArray(str,data,0,WHOLE_ARRAY,CP_UTF8)-1);
              
      ResetLastError();
      
      res=WebRequest("POST","http://www.mywebpage.com/index5.htm","",NULL,1000,data,ArraySize(data),result,headers);
      
      Print("Status code: " , res, ", error: ", GetLastError());
      Print("Server response: ", CharArrayToString(result));
AED AED
242
AED AED 2015.10.07 19:21  
Any help is appreicated. Thanks.
Carl Schreiber
5951
Carl Schreiber 2015.10.08 06:21  

The server answers with an error, so you touch the server but the requested web-page seems not to exist.

This works for me:

string GrabWeb(string strUrl) {//>4
   string headers,ret;  
   char post[],result[];
   int res, timeout=5000;
   res=WebRequest("GET",strUrl,NULL,timeout,post,result,headers);
   if (res < 0) { 
        Alert("Web-Error: ",GetLastError()," (4060 ERR_FUNCTION_NOT_CONFIRMED/Url not allowed)" );
        return("");
   } 
   ret = CharArrayToString(result,0,-1);  
   return(ret);
}
AED AED
242
AED AED 2015.10.08 09:55  
gooly:

The server answers with an error, so you touch the server but the requested web-page seems not to exist.

This works for me:




Thanks for your post.

I'm trying to POST a line to an existing html document not GET. Could you send a simple example for POST as well. I'm not quite sure how can I POST a new line to the existing html document,

Suppose that the URL is www.mywebpage.com/index.htm

I understand that index.html must exists. This is fine also I do not get any authentication problems. The only error I guess is about syntax, I need to refine "the string" accordingly however I don't know how to do it, I couldn't find any documentation as well.

Carl Schreiber
5951
Carl Schreiber 2015.10.08 14:44  
aed71:

Thanks for your post.

I'm trying to POST a line to an existing html document not GET. Could you send a simple example for POST as well. I'm not quite sure how can I POST a new line to the existing html document,

Suppose that the URL is www.mywebpage.com/index.htm

I understand that index.html must exists. This is fine also I do not get any authentication problems. The only error I guess is about syntax, I need to refine "the string" accordingly however I don't know how to do it, I couldn't find any documentation as well.


hmm - can't you copy the url from the url-line of the browser and pack  that between two " - like strUrl = "https://forum.mql4.com/69624#1022641"?

If I  call this page: "http://www.mywebpage.com/index5.htm" I see this url isn't valid any more!

AED AED
242
AED AED 2015.10.08 18:28  
gooly:

hmm - can't you copy the url from the url-line of the browser and pack  that between two " - like strUrl = "https://forum.mql4.com/69624#1022641"?

If I  call this page: "http://www.mywebpage.com/index5.htm" I see this url isn't valid any more!

It was just an example, I didn't want to give real webpage name. I'm willing to know what would be the syntax for the data[] array if I want to POST something to an html file. I already understand how to add syntax for authentication but there is no information for the html part, header, normal letters etc.

/
To add comments, please log in or register