0
Answered

Force Content-Length in header

Wouter van der Post 10 months ago in Products / AV & Custom Systems updated by Vladimir Ovchinnikov 6 months ago 1

Hello,

The webserver (API) I am calling from iRidium requires the Content-Length header to be present. Even a value of '0' is OK, as long as the header property is in the request.

If I execute the following:

  IR.GetDevice("Custom AV").SendEx({ 
    Type: "POST",                                                                    
    Url:  "/api/v1/sp/1/1,
    Headers: {"Content-Type":"application/json", "X-Api-Key":"somekey"},
    cbReceiveCode:       
      function(code) {
        if (code != 200) {
          IR.Log("Error response (" + code + ") received");
        }
      },
    cbReceiveText:       
      function(text, code, headers) {
        if (code != 200) {
          IR.Log("Error response (" + code + ") received\r\nDetails: " + text);
        }
      }
  });

There is no Content-Length header in the request.

I tried to force it by adding an empty data object:

  var data = "";

  IR.GetDevice("Custom AV").SendEx({ 
    Type: "POST",                                                                    
    Url:  "/api/v1/sp/1/1,
    Data: [data],
    Headers: {"Content-Type":"application/json", "X-Api-Key":"somekey"},
    cbReceiveCode:       
      function(code) {
        if (code != 200) {
          IR.Log("Error response (" + code + ") received");
        }
      },
    cbReceiveText:       
      function(text, code, headers) {
        if (code != 200) {
          IR.Log("Error response (" + code + ") received\r\nDetails: " + text);
        }
      }
  });

But this also does not add the header.


According to the documentation I can't add this property to the Header field.

Can you tell me if there is another way to add "Content-Length":0 to the request header?

Answered

Hello.

Release 1.3.25 adds the ability to send a POST request with an empty BODY.