WebRequest Function, always return 500 value

To add comments, please log in or register
zboo
21
zboo  
Hello everyone, I encountered a problem when using the WebRequest function, and I would like to ask everyone to help.



The website engineer gave me the following information:

URL:http://ea.takeasy.tech/api/ea/accounts

Method:GET

Headers:Content-Type: application/json\r\nAuthorization: Bearer {API Get Token}

(Token in the code, Token is only valid for 24 hours. After that time, I will update the token again.)


I print the "res" value

But keep showing 500, it can’t show 200 successfully.

What is the problem?

Thank you for your help ~


My Code:

string token= "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9lYS50YWtlYXN5LnRlY2hcL2FwaVwvbG9naW4iLCJpYXQiOjE1NzUyODI3NTUsImV4cCI6MTU3NTM2OTE1NSwibmJmIjoxNTc1MjgyNzU1LCJqdGkiOiJFTnFNWlhoUjE5UDRqR2c5Iiwic3ViIjoidTVkZGUxYjFhYWMwZjE5MTY0ZmI0OTdlMGI4MWU2ZWI1IiwicHJ2IjoiODdlMGFmMWVmOWZkMTU4MTJmZGVjOTcxNTNhMTRlMGIwNDc1NDZhYSJ9.uwAIFU4lun0DPK1KlmHOTohlZkl6UseqFdynzWs1_f4";

   int    res;                                                                 //接收回傳結果
   
   string method= "GET";                                                       //方法,使用GET或POST
   string url= "http://ea.takeasy.tech/api/ea/accounts";                       //URL
   string headers= "Content-Type: application/json\r\nAuthorization: Bearer "; //標題
   int    timeout= 0;                                                          //超時
   char   data[];                                                              //要傳給DB的登入數據
   char   results[];                                                           //記錄從DB回傳「表格中的資料」
   string result_headers= "";                                                  //記錄從DB回傳此次連線資訊
   
   string str= "token="+token;
   ArrayResize(data,StringToCharArray(str,data,0,WHOLE_ARRAY,CP_UTF8)-1);
   
   ResetLastError();
   res= WebRequest(method,url,headers,timeout,data,results,result_headers);
   
   Print("res===" + IntegerToString(res));


The screenshot below is the query result using "Postman" software, which can be queried normally.





Soewono Effendi
2716
Soewono Effendi  
zboo:
Hello everyone, I encountered a problem when using the WebRequest function, and I would like to ask everyone to help.



The website engineer gave me the following information:

URL:http://ea.takeasy.tech/api/ea/accounts

Method:GET

Headers:Content-Type: application/json\r\nAuthorization: Bearer {API Get Token}

(Token in the code, Token is only valid for 24 hours. After that time, I will update the token again.)


I print the "res" value

But keep showing -1, it can’t show 200 successfully.

What is the problem?

Thank you for your help ~


My Code:


The screenshot below is the query result using "Postman" software, which can be queried normally.





Refer to:

https://www.mql5.com/en/docs/network/webrequest

To use the WebRequest() function, add the addresses of the required servers in the list of allowed URLs in the "Expert Advisors" tab of the "Options" window.

Server port is automatically selected on the basis of the specified protocol - 80 for "http://" and 443 for "https://".

Documentation on MQL5: Network Functions / WebRequest
Documentation on MQL5: Network Functions / WebRequest
  • www.mql5.com
To use the WebRequest() function, add the addresses of the required servers in the list of allowed URLs in the "Expert Advisors" tab of the "Options" window. Server port is automatically selected on the basis of the specified protocol - 80 for "http://" and 443 for "https://". The WebRequest() function is synchronous, which means its breaks the...
zboo
21
zboo  
Soewono Effendi:

Refer to:

https://www.mql5.com/en/docs/network/webrequest

To use the WebRequest() function, add the addresses of the required servers in the list of allowed URLs in the "Expert Advisors" tab of the "Options" window.

Server port is automatically selected on the basis of the specified protocol - 80 for "http://" and 443 for "https://".

Hi Soewono Effendi~

[add the addresses of the required servers in the list of allowed URLs in the "Expert Advisors" tab of the "Options" window.]

I have added the URL later, it is currently showing 500

How do I deal with the next step?

Thank you~

Soewono Effendi
2716
Soewono Effendi  
zboo:

Hi Soewono Effendi~

[add the addresses of the required servers in the list of allowed URLs in the "Expert Advisors" tab of the "Options" window.]

I have added the URL later, it is currently showing 500

How do I deal with the next step?

Thank you~

what do you mean by "showing 500" ?
Is it  HTTP error, like 404, 500, etc ?
If yes, it means your webrequest is executed correctly, but maybe the way you make wrong webrequest, i.e. wrong uri / data parameters or maybe request method, GET / POST .

For WebRequest error codes please refer to
https://www.mql5.com/en/docs/constants/errorswarnings/errorcodes


Refer to this for HTTP error 500

https://www.westhost.com/knowledgebase/plugins/servlet/mobile?contentId=1114700#content/view/1114700
zboo
21
zboo  
Soewono Effendi:
what do you mean by "showing 500" ?
Is it  HTTP error, like 404, 500, etc ?
If yes, it means your webrequest is executed correctly, but maybe the way you make wrong webrequest, i.e. wrong uri / data parameters or maybe request method, GET / POST .

For WebRequest error codes please refer to
https://www.mql5.com/en/docs/constants/errorswarnings/errorcodes


Refer to this for HTTP error 500

https://www.westhost.com/knowledgebase/plugins/servlet/mobile?contentId=1114700#content/view/1114700

Hi Soewono Effendi~

I have found a solution

Thanks for your answers ~~~

I also put the solution to others for reference

Thank you!

string headers= "Content-Type: application/json\r\nAuthorization: Bearer " + token;
string    token= {Your Token};
   int    res;                                                                         
   
   string method= "GET";                                                               
   string url= "http://ea.takeasy.tech/api/ea/accounts";                               
   string headers= "Content-Type: application/json\r\nAuthorization: Bearer " + token; 
   int    timeout= 0;                                                                  
   char   data[];                                                                      
   char   results[];                                                                   
   string result_headers= "";                                                          
   
   ResetLastError();
   res= WebRequest(method,url,headers,timeout,data,results,result_headers);

   Print("res===" + IntegerToString(res));
To add comments, please log in or register