0

PhantomJs's webserver does not support multipart requests, so I'm trying to send a single-part request from NodeJs.

Unfortunatly the nodejs example looks to be multipart. is there any way of doing this with NodeJs?

http://nodejs.org/api/http.html#http_http_request_options_callback

edit: in the nodejs docs it mentions: Sending a 'Content-length' header will disable the default chunked encoding. but unfortunatly it's still multi-part, just not multi-multipart :P

edit2: for showing code, it's a bit hard to show a distilled example, but here goes:

node.js code (it's Typescript code):

```

    //send our POST body (our clientRequest)
    var postBody = "hello";

    var options : __node_d_ts.IRequestOptions = {
        host: host,
        port: port,
        path: "/",
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            "Content-length": postBody.length
        }
    };


    //logger.assert(false);
    var clientRequest = http.request(options,(response: http.ServerResponse) => {
        //callback stuff here
    });

    clientRequest.on("error", (err) => {
        thisObj.abort("error", "error,request error", err);
    });

    //clientRequest.write();
    clientRequest.end(postBody);

```

when i read the results from PhantomJS, the post/postRaw fields are null. when I use a tool like the Chrome "Advanced REST Client" extension to send a POST body, phantomjs gets it no problem.

i don't have a network sniffer, but as described here, it says phantomjs doesnt work with multipart so I think that's a good guesss: How can I send POST data to a phantomjs script

EDIT3:

indeed, here's the request phantomjs gets from my chrome extension (valid post) //cookie, userAgent, and Origin headers removed for brevity {"headers":{"Accept":"*/*","Accept-Encoding":"gzip,deflate,sdch","Accept-Language":"en-US,en;q=0.8,ko;q=0.6","Connection":"keep-alive","Content-Length":"5","Content-Type":"application/json","DNT":"1","Host":"localhost:41338", "httpVersion":"1.1","method":"POST","post":"hello","url":"/"}

and here's the request phantomjs gets from the nodejs code i show above:

//full request, nothing omitted! {"headers":{"Connection":"keep-alive","Content-Type":"application/json","Content-length":"5","Host":"10.0.10.15:41338"},"httpVersion":"1.1","method":"POST","url":"/"}

Community
  • 1
  • 1
JasonS
  • 7,443
  • 5
  • 41
  • 61
  • What makes you say Node's example is multipart? Can you show any code for what you've tried? – loganfsmyth Mar 03 '14 at 08:16
  • @loganfsmyth, added more details. – JasonS Mar 03 '14 at 08:54
  • Sorry, can you please clarify what code you are using in Phantom that is not returning what you expect? Also, are you talking about `Transfer-Encoding: chunked` or `Content-Type: multipart/form-data` being the problem. You've mentioned both and it is a little confusing. I have *no* idea what `"unfortunatly it's still multi-part, just not multi-multipart"` means. – loganfsmyth Mar 03 '14 at 15:39
  • in my EDIT3 section I do a console log of the request object. you can see that the nodejs request does not include the "post":"hello" value. when i send a POST from another tool (a browser extension) PhantomJs gets it fine. so it comes down to phantomjs not getting the post body from a nodejs POST request. – JasonS Mar 04 '14 at 02:07

0 Answers0