如何在mql5中为WebRequest Post请求设置主体?

时间:2019-01-02 11:52:16

标签: post httpwebrequest postman mql mql5

我要向“ https://sslecal2.forexprostools.com/ajax.php”发出发布请求。所以有我的代码:

string MakePostRequest(string _url)
{
  string _url = "https://sslecal2.forexprostools.com/ajax.php";
  string _headers = "X-Requested-With: XMLHttpRequest\r\nContent-Type: application/x-www-form- urlencoded";
  string _params = "dateFrom=2018-12-24\r\ndateTo=2018-12-24\r\ntimeZone:18\r\naction:filter";

  string stringresult = "";

  char data[];
  StringToCharArray(_params, data, 0, StringLen(_params) - 1);
  char result[];

  string result_headers;

  ResetLastError();

  int res = WebRequest("POST", _url, _headers, 30000, data, result, result_headers);

  if (res == -1)
  {
      Print("Error in WebRequest. Error code =", GetLastError());
      //--- URL may not exist in white list, so there is a message for it
      MessageBox("Add '" + _url + "' to white list in options in experts page. ", "Error: ", MB_ICONINFORMATION);
  }
  else
  {
      if (res == 200)
      {
          //--- Succesfully downloaded
          PrintFormat("Succesfully downloaded, size %d.", ArraySize(result));
          //--- Save result[] to file
          int filehandle = FileOpen("debug_output.htm", FILE_WRITE | FILE_BIN);
          if (filehandle != INVALID_HANDLE)
          {
              FileWriteArray(filehandle, result, 0, ArraySize(result));
              FileClose(filehandle);
          }
          else
          {
              Print("Error in FileOpen. Error code =", GetLastError());
          }
          stringresult = CharArrayToString(result);
      }
      else
          PrintFormat("Error in download '%s', code %d", _url, res);
  }
  return stringresult;
}

我在字符串“ WebRequest(” POST“,_url,_headers,30000,data,result,result_headers)中的” data“中做了一些不正确的操作;”因为我得到200个空的html答案。

然后我将带有html代码的Post的相同请求的屏幕附加到Postman中。 Postman body with answer Postman headers

0 个答案:

没有答案