Superagent: Get Raw Request to debug

Created on 23 Mar 2012  路  8Comments  路  Source: visionmedia/superagent

Is there a way to get the raw request data?
I've got a problem where a post works with restler but not with superagent and I am looking for an easy way to debug it.

Most helpful comment

In case anybody else ends up here you can use

.end(function (error, result) {
   console.log(result.req);
});

Although the request is a pretty big graph so you'll probably just want to look at one or two properties

All 8 comments

hmm did you try res.text?

I was looking for something similar to the output of for instance Charles like:

POST /test HTTP/1.1
Host: localhost:4000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20100101 Firefox/11.0
Accept: application/json, text/javascript, _/_; q=0.01
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://localhost:4000/
Content-Length: 14
Cookie: some.sid=OdS3YHpTdsadsadr32423asd
Pragma: no-cache
Cache-Control: no-cache

{"body":"Foo"}

node doesn't give you a string of the header but you could just log out console.log(res.headers), and in many cases you dont dont want a string representation laying around, if it's a large multipart response etc

makes sense, thanks!

I don't get it. Case is closed by showing how to debug res.headers where the question was about the debugging the request. Oh well.

In case anybody else ends up here you can use

.end(function (error, result) {
   console.log(result.req);
});

Although the request is a pretty big graph so you'll probably just want to look at one or two properties

Thank you @robotlovesyou, that was useful!

closest i could get was

console.log(result.req._header + JSON.stringify(json))

where json was the body I sent.

Was this page helpful?
0 / 5 - 0 ratings