HttpRequest not working
HttpRequest not working
09 Feb 2025, 05:02
I can access mql5's economic news with the code below.
https://help.ctrader.com/ctrader-algo/guides/network-access/?h=httprequest#performing-a-post-request
According to the example here, I can't access when I use HttpRequest. Will using WebClient cause a problem?
try {
using var webClient = new WebClient();
// Headers
webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
webClient.Headers.Add("x-requested-with", "XMLHttpRequest");
webClient.Headers.Add(HttpRequestHeader.UserAgent, "_fz_uniq=5059388315850202230");
// POST Data
var postData = new NameValueCollection
{
{"date_mode", "0"},
{"from", "2023-09-01T00:00:00"},
{"to", "2023-09-02T23:59:59"},
{"importance", "13"},
{"currencies", "262143"}
};
// Send POST Request
byte[] responseBytes = webClient.UploadValues("https://www.mql5.com/en/economic-calendar/content", "POST", postData);
string response = System.Text.Encoding.UTF8.GetString(responseBytes);
// Process Response
Print("Server Response: ", response);
}
catch (Exception ex)
{
Print($"General Error: {ex.Message}");
}
firemyst
18 Feb 2025, 05:11
Since you don't say where or how you'll be running the bot – if you're running a bot in the cloud, there's no access allowed. You can only do it when run locally or on a vps.
@firemyst