Is it possible to use WebRequest post HTML content to a website?

To add comments, please log in or register
silverfall
28
silverfall  

What I'm trying to do is submit HTML content from EA to my joomla website, I did some search but couldn't find if it's possible to use WebRequest to do it.


Any help is great.


Thanks.

Fernando Carreiro
5067
Fernando Carreiro  
silverfall: What I'm trying to do is submit HTML content from EA to my joomla website, I did some search but couldn't find if it's possible to use WebRequest to do it.

Yes, it is possible! Just use a "POST" or "PUT" method. Read up on HTTP protocol. Read-up on the following pocket links from other threads for more information that should help you:

Forum on trading, automated trading systems and testing trading strategies

Metatrader 4 to Binary.com

Fernando Carreiro, 2016.09.14 10:04

You must first set permissions on MetaTrader's Options in order to allow access to that website. Go to the "Tools->Options" (or Ctrl+O) and then go to the "Expert Advisors" tab. At the very end of those options, to will find and have to enable the "Allow WebRequest for the listed URL:" and then proceed to add the URL of the site.

NB! Also, depending on the data being retrieved, you may need to use the 2nd version of WebRequest as the first one is only valid for form data (Content-Type: application/x-www-form-urlencoded).

Forum on trading, automated trading systems and testing trading strategies

How can i send cookie session from WebRequest?

Fernando Carreiro, 2016.06.06 00:31

Maybe you should first learn about the HTTP protocol and how it all works. The cookie session (or any other header) can be transferred back and forth via the "headers" and "result_headers" arguments/parameters:

You will have to parse "result_headers" in accordance with the HTTP Headers format in order to extract the cookie information (or other header information you may need). Then when submitting a new request you will have to build the "headers" parameter according to the HTTP rules.

Here are some helpful links to get you started:

Please, note that this is not really a MQL coding related issue and you should look for advice and help about HTTP on other forums dedicated to such matters.

Forum on trading, automated trading systems and testing trading strategies

Auto trading the news

Fernando Carreiro, 2016.09.02 00:18

You will have to collect that data from Websites that are offering those services (be they paid or free). You can use the function WebRequest() to obtain data from the web, but you will have to learn about HTTP, and depending on the API the website provides, you may also need to learn REST,  JSON or XML or even standard HTML. These web protocols are however beyond the scope of this forum, so for more information you will have to search the Internet. Here are some links to get you started:

Please note, that collecting and parsing Web data via an API, is not something for a beginner or newbie coder. It requires at least an intermediate level of coding knowledge and good understanding about web protocols.

I also suggest reading the following threads on here:

EDIT: There are also relevant entries in the Codebase that will be of interest to you (had you done a search):

NB! However, please note that WebRequest() only works in EA's and Scripts but not in Indicators.

nicholish en
2677
nicholish en  

Here is a high-level library I've been working on... It's undocumented, but if you're a relatively decent coder you should be able to figure it out pretty quick. One of the neat things is how you can chain all the setter methods in order to quickly setup your session. Here's an example test using postman-echo...

bool test_post_json()
{
   string res_name = NULL;
   string acc_name = AccountInfoString(ACCOUNT_NAME);
   
   WebSession x("https://postman-echo.com/post");
   x.headers_request()["Content-Type"] = "application/json";
   
   Json json;
   json["account_name"] = acc_name;
   if(x.request_body(json).POST().status_code() == 200){
      json.Deserialize(x.json()["data"].ToStr());
      res_name = json["account_name"].ToStr();
   }
   return acc_name == res_name;
}


 

Sergey Golubev
Moderator
116981
Sergey Golubev  

Forum on trading, automated trading systems and testing trading strategies

How to start with MetaTrader and forex, the beginning

Sergey Golubev, 2019.05.06 20:11

Extracting structured data from HTML pages using CSS selectors

Extracting structured data from HTML pages using CSS selectors

The MetaTrader development environment enables the integration of applications with external data, in particular with the data obtained from the Internet using the WebRequest function. HTML is the most universal and the most frequently used data format on the web. If a public service does not provide an open API for requests or its protocol is difficult to implement in MQL, the desired HTML pages can be parsed. In particular, traders often use various economic calendars. Although the task is not so relevant now, since the platform features the built-in Calendar, some traders may need specific news from specific sites. Also, we sometimes need to analyze deals from a trading HTML report received from third parties.

The MQL5 ecosystem provides various solutions to the problem, which however are usually specific and have their limitations. On the other hand, there is kind of "native" and universal method to search and parse data from HTML. This method is connected with the use of CSS selectors. In this article we will consider the MQL5 implementation of this method, as well as examples of their practical use.


To add comments, please log in or register