Error posting HTTP DELETE from server side


#1

Hello,
I’m trying to make an HTTP DELETE call server side but I’m getting two errors which is prohibiting this. First, when II try to set the content length to zero I get:

(STDERR) Refused to set unsafe header “Content-length”

Then when I send the DELETE, the callback comes back with a 411 error indicating that no Content-length set on the DELETE. The code is below. Is there a better way to attempt this?

xmlhttp = Meteor.npmRequire('xmlhttprequest').XMLHttpRequest;
...
var xhrDelete = new xmlhttp();
xhrDelete.open('DELETE', msgURL, true);
xhrDelete.setRequestHeader('Content-length', '0');
xhrDelete.onreadystatechange =
   function () {
      if (xhrDelete.readyState == 4) {
         var serverResponse = xhrDelete.responseText;
         var status = xhrDelete.status;
         if (status != 200) {
            console.log("MEF Msg DELETE error: " + status + " Message: " + serverResponse);
         }
         console.log("DELETE Msg status: " + status);
      }
   }
xhrDelete.send(null)

#2

Just curious - why the npm method and not Meteor’s inbuilt HTTP methods?


#3

I didn’t know there was one at the time of the posting. I’ve since found it, but it too is giving me trouble. The response callback is receiving a getaddrinfo ENOTFOUND error. The server I’m trying to hit is running as a virtual machine on the same computer meteor is running on. Note that the xmlhttprequest and EventSource modules that I use have no trouble reaching the address, and I can ping it from my meteor machine.

Here’s the HTTP code I’m using:

   var msgURL = 'http://mef.ons.pnet/myapp/messages/' + msgId;
   var results = HTTP.del(msgURL , function (error, result) {
        if (error) {
               console.log(error.response.status);
        }
  })

;


#4

When you say that you can ping it etc., is this with a valid msgId appended to the base address as your code uses? Have you confirmed that this is correctly set in your code?


#5

Yes. e.g. putting this:

http://mef.ons.pnet/ground_control/messages/8bff5a47-6049-46b6-9567-d40dae5a66b2

in my browser (which was taken directly from my meteor debugger as the URL I’m using in the call) nets me this in the resulting page:

{“MT-Current-Config”:“001.250.300”,“GC-Conversation-Id”:“9tCFYmdwKau9TBstj”}

Which is the expected return value for a get. I’m not sure how to do a DELETE from the browser though so haven’t test that.