How to set user agent property in WebRequest

 

Hi,

I am using the following MQL5 code to fetch data from a web service:


   string cookie=NULL,headers;
   char   post[],result[];
   string referer = NULL;
   string url="http://www.test.com";
   int res=WebRequest("GET",url,cookie,referer,500,post,0,result,headers);

However, I need to specify the user agent property in the header of the request. How can we do that? In know in C# we can do so as follows:

using System;  
using System.IO;  
using System.Net;  
using System.Text;  
  
namespace Examples.System.Net  
{  
    public class WebRequestGetExample  
    {  
        public static void Main ()  
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.test.com");
            request.UserAgent = "Mozilla / 5.0(Windows NT 10.0; Win64; x64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 70.0.3538.77 Safari / 537.36";
            request.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            request.Headers.Add(HttpRequestHeader.AcceptLanguage, "de-DE");

            using (var response = (HttpWebResponse)(request.GetResponse()))
            {
                                
            }
        }  
    }
} 
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Path to the file of an image that will be used as an icon of the EX5 program. Path specification rules are the same as for resources. The property must be specified in the main module with the MQL5 source code. The icon file must be in the ICO format. When launching a script or an Expert Advisor on the chart, the stack of at least 8 MB is...
Reason: