正确的方法在MQL4中PUT WebRequest()

时间:2018-05-22 16:02:38

标签: mql4

我尝试使用myjson.com更新WebRequest()的JSON,导致失败。

return result: 2018.05.22 23:54:44.401    webreq NZDCAD,H1: Status code: 404, error: 4000

我想更改" John"到"拉布"

我的代码如下:

void postJson()
{
   char post[], result[];

   string headers = "Content-Type: application/json\r\n";
   string obj     = "'data:{\"name\":\"Labu\"}'"; 

   StringToCharArray( obj, post, 0, WHOLE_ARRAY ); // Must specify string length;
                                                   // otherwise array has
                                                   // terminating null character in it
   int res = WebRequest( "POST",
                         "https://api.myjson.com/bins/tj8e2",
                         "PUT",
                          NULL,
                          10000,
                          post,
                          ArraySize( post ),
                          result,
                          headers
                          );
   Print( "Status code: " , res, ", error: ", GetLastError() );
   Print( "Server response: ", CharArrayToString( result ) );
}

2 个答案:

答案 0 :(得分:0)

string obj="'data:{\"name\":\"Labu\"}'";  

您不需要 ' -chars 您必须确保该地址有效并且已将其添加到允许的网站列表中(在MetaTrader终端配置设置面板内)。

答案 1 :(得分:0)

删除POST并放入PUT, 阅读您自己的代码:WebRequest( "POST", 应该是WebRequest( "PUT",

您仍在使用POST方法。

这里:

    int  WebRequest(
   const string      method,           // HTTP method 
   const string      url,              // URL
   const string      cookie,           // cookie
   const string      referer,          // referer
   int               timeout,          // timeout
   const char        &data[],          // the array of the HTTP message body
   int               data_size,        // data[] array size in bytes
   char              &result[],        // an array containing server response data
   string            &result_headers   // headers of server response
   );

现在将是一个很好的时机,还要提到mt4不支持PUT或DELETE仅支持POST和GET;)