WebRequest no PUT method ?

 

I have much success using WebRequest function from mt4 but i would like to ask does mt4 not support PUT method ?

POST and GET work great, but PUT always fails, the error suggests my parameters are wrong, i use the same as a POST i checked on my API using curl and it works fine yet MT4 seems to not understand the method PUT, is this true? I know DELETE is not supported so i wonder is PUT also not supported?

 
HTTP Verb CRUD Entire Collection (e.g. /customers) Specific Item (e.g. /customers/{id})
POST Create 201 (Created), 'Location' header with link to /customers/{id} containing new ID. 404 (Not Found), 409 (Conflict) if resource already exists..
GET Read 200 (OK), list of customers. Use pagination, sorting and filtering to navigate big lists. 200 (OK), single customer. 404 (Not Found), if ID not found or invalid.
PUT Update/Replace 405 (Method Not Allowed), unless you want to update/replace every resource in the entire collection. 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.
PATCH Update/Modify 405 (Method Not Allowed), unless you want to modify the collection itself. 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.
DELETE Delete 405 (Method Not Allowed), unless you want to delete the whole collection—not often desirable. 200 (OK). 404 (Not Found), if ID not found or invalid.
 
Mladen Rakic:
HTTP Verb CRUD Entire Collection (e.g. /customers) Specific Item (e.g. /customers/{id})
POST Create 201 (Created), 'Location' header with link to /customers/{id} containing new ID. 404 (Not Found), 409 (Conflict) if resource already exists..
GET Read 200 (OK), list of customers. Use pagination, sorting and filtering to navigate big lists. 200 (OK), single customer. 404 (Not Found), if ID not found or invalid.
PUT Update/Replace 405 (Method Not Allowed), unless you want to update/replace every resource in the entire collection. 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.
PATCH Update/Modify 405 (Method Not Allowed), unless you want to modify the collection itself. 200 (OK) or 204 (No Content). 404 (Not Found), if ID not found or invalid.
DELETE Delete 405 (Method Not Allowed), unless you want to delete the whole collection—not often desirable. 200 (OK). 404 (Not Found), if ID not found or invalid.
so does mt4 support PUT ?? cause they dont supprot DELETE...
are you just a bot ??
 
I do appreciate your table but still i need to know does mt4 actually support PUT and DELETE or not ?
Sorry to bump may anyone kindly reply ? thanks kindly i truly appreciate it.
 
vual:
I do appreciate your table but still i need to know does mt4 actually support PUT and DELETE or not ?
Sorry to bump may anyone kindly reply ? thanks kindly i truly appreciate it.

According to manual, WebRequest only supports GET and POST, at ports 80 or 443.

 
Mohammad Hossein Sadeghi:

According to manual, WebRequest only supports GET and POST, at ports 80 or 443.

Thanks kindly what a shame that really is :( what options do i have to make a put request ? Wininet.Dll maybe ?
https://www.mql5.com/en/forum/165618
Does WebRequest function support HTTP DELETE?
Does WebRequest function support HTTP DELETE?
  • 2017.01.06
  • www.mql5.com
I have HTTP Delete method API call via WebRequest, but it reported an error with "Error in WebRequest. Error code =4051...
 
Any idea why this does not work with SSL? Thanks alot for any assistance.
Code attached:
//custom PUT method, web request doest not support PUT
bool HttpPUT(string host, string script, string& strWebPage, string headers, string jsonData)
{
  printf(jsonData);
  int hIntrn = InternetOpenW("cloneTrade-mt4-ea", 1, "0", "0", 0);
  if (hIntrn == 0) {
    return (false);
  }

  int hConn = InternetConnectW(hIntrn,
                              host,
                              443,
                              "",
                              "",
                              3,
                              0,
                              1);

  if (hConn == 0) {
    return (false);
  }

 //int dwOpenRequestFlags =   // _IGNORE_REDIRECT_TO_HTTP |
                             // _IGNORE_REDIRECT_TO_HTTPS |
                             // INTERNET_FLAG_KEEP_CONNECTION |
                             // INTERNET_FLAG_NO_AUTO_REDIRECT |
                             // INTERNET_FLAG_NO_COOKIES |
                             // INTERNET_FLAG_NO_CACHE_WRITE |
                             //INTERNET_FLAG_NO_UI
                             //;

  string accept[];
  //string headers = "Content-Type: application/x-www-form-urlencoded";
  string data = jsonData;
  //string acceptTypes[1] = {"*/*"};
  char acceptTypes[];
  int hReq = HttpOpenRequestW(hConn,
                             "PUT",
                             script,
                             "HTTP/1.1",
                             "",
                             acceptTypes,
                             0,
                             0);

  
  int request[];
  if (!HttpSendRequestW(hReq, headers , StringLen(headers), data, StringLen(data))) {
    Print(GetLastError());
    printf("Last MSDN Error =: ", kernel32::GetLastError());
    return (false);
  }

  // Read response

  int     lReturn[]  = {1};
  string  sBuffer    = "";

  while (TRUE) {
    if (InternetReadFile(hReq, sBuffer, StringLen(sBuffer), lReturn) <= 0 || lReturn[0] == 0) {
      break;
    }
    strWebPage = StringConcatenate(strWebPage, StringSubstr(sBuffer, 0, lReturn[0]));
  }

  InternetCloseHandle(hReq);
  InternetCloseHandle(hConn);
  InternetCloseHandle(hIntrn);

  return (true);
}
 

Yes it is possible, just set the httpType to "POST" then write send this as Header : 

X-HTTP-Method-Override:PUT

You Can also send PATCH or DELETE with this approach.


Example:

string response = SendResquest("POST", "https://google.com", body, "X-HTTP-Method-Override:PUT", 5000);


string SendResquest(string httpType, string address, string bodyData = "", string headers = "", int timeout=5000)
{
    uchar bodyDataCharArray[];
    uchar resultDataCharArray[];
    string resultHeader;
    ArrayResize(bodyDataCharArray, StringToCharArray(bodyData, bodyDataCharArray)-1);

    int response = WebRequest(httpType, address, headers, timeout, bodyDataCharArray, resultDataCharArray, resultHeader);

    string result = CharArrayToString(resultDataCharArray); 

    if(response == 200)
        return result;
    Print("Error when trying to call API : ", GetLastError());
    return "";
}


Thanks to Mohammad Hasan Daneshvar to tell me this.

Reason: