DEV Community

Rabist
Rabist

Posted on • Updated on

MQL5 HTTP Web Request Using WinINet DLL

An easy-to-use, general-purpose library for sending HTTP web requests in MQL5 using the WinINet DLL.

Introducing an easy-to-use, general-purpose library designed for seamless handling of HTTP web requests in MQL5 through the utilization of the WinINet DLL. This library simplifies the process of incorporating web request functionalities into your MQL5 projects, providing a user-friendly interface for developers. With its intuitive design, the library empowers users to effortlessly send and manage HTTP requests, offering a versatile solution for a wide range of applications within the MQL5 environment. Streamlining the integration of web communication capabilities, this library serves as a valuable resource for developers seeking efficient and reliable methods to interact with online resources in their MQL5 projects.

Example 1:

Send a GET request and retrieve current GMT time.

WininetRequest req;
WininetResponse res;

req.host = "worldtimeapi.org";
req.path = "/api/timezone/Europe/London.txt";

WebReq(req, res);

Print("status: ", res.status);
Print(res.GetDataStr());
Enter fullscreen mode Exit fullscreen mode

Example 2:

Send a POST request and echo it back.

WininetRequest req;
WininetResponse res;

req.method = "POST";
req.host = "httpbin.org";
req.path = "/post";
req.port = 80;
req.headers = "Accept: application/json\r\n"
              "Content-Type: application/json; charset=UTF-8\r\n";

req.data_str = "{'id': 10, 'title': 'foo', 'message': 'bar'}";
StringReplace(req.data_str, "'", "\"");

WebReq(req, res);

Print("status: ", res.status);
Print(res.GetDataStr());
Enter fullscreen mode Exit fullscreen mode

Top comments (0)