I have made a Python Django API model. I am trying hard for the last few weeks to read the JSON object using Webrequest but I am getting error 4029 Invalid array. Previously I had connected Telegram with MT5 using the Webrequest and it worked. But it is not working for Django. I run the Django API using the runserver command on the localhost. Can anyone help?
- Discussion of article "How to create bots for Telegram in MQL5"
- WebRequest Post Example with Data
- Can MT4 send WebRequest or Need DLL ?
This is the JSON object that I want to read:
{"signals":[{"id":1,"signal":"buylimit\r\nGBPUSD\r\n240\r\n1\r\n0\r\n3\r\n2\r\nLiteFinance"},{"id":2,"signal":"selllimit\r\nEURUSD\r\n240\r\n0\r\n0\r\n3\r\n1"},{"id":3,"signal":"selllimit\r\nEURNZD\r\n240\r\n2\r\n0\r\n3\r\n1"}]}
These are the request headers from Django:
Allow: GET, HEAD, OPTIONS Content-Length: 228 Content-Type: application/json Cross-Origin-Opener-Policy: same-origin Date: Mon, 06 Nov 2023 11:27:34 GMT Referrer-Policy: same-origin Server: WSGIServer/0.2 CPython/3.8.8 Vary: Accept, Cookie X-Content-Type-Options: nosniff X-Frame-Options: DENY Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.5 Connection: keep-alive Host: 127.0.0.1:8000 Referer: http://127.0.0.1:8000/signals/signals Sec-Fetch-Dest: document Sec-Fetch-Mode: navigate Sec-Fetch-Site: same-origin Sec-Fetch-User: ?1 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0
This is the MQL5 code that I am trying to execute:
CJAVal js; string request_headers="Content-Type: application/json" + "\r\n"; //"Accept:application/json, text/javascript, */*; q=0.0\r\nContent-Type:application/x-www-form-urlencoded"; //string request_headers="Content-Type: application/json"; string response_headers; //char post[], result[]; char post[]; char signals[]; string url = "http://127.0.0.1:8000/signals/signals"; //int r = WebRequest("POST", "http://127.0.0.1/api/symbol/","Content-Type: application/json",5000, data,res_data, res_headers); //int res = WebRequest("GET", url, request_headers, 5000, post, signals, response_headers); int res = WebRequest("GET", url, NULL,request_headers, 10000, post, ArraySize(post), signals, response_headers); //int res = WebRequest("GET", url, NULL, "", 5000, post, ArraySize(post), signals, headers); //4029 ERR_ARRAY_INVALID Invalid arrayI am looking for help in solving this problem.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register