return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - Not getting proper response in node js by using node-rest-client middleware - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Not getting proper response in node js by using node-rest-client middleware - Stack Overflow

programmeradmin1浏览0评论

I am a newby in Node js, after hit HubSpot api through node js by using node-rest-middleware am getting below kind of response. Why?

<Buffer 7b 22 76 69 64 22 3a 35 2c 22 63 61 6e 6f 6e 69 63 61 6c 2d 76 69 64 22 3a 35 2c 22 6d 65 72 67 65 64 2d 76 69 64 73 22 3a 5b 5d 2c 22 70 6f 72 74 61 ... >

Here is my snippet please take a look

var args = {
    data: formData,
    headers:{"Content-Type": "application/json"}
};

client.post(hubURL, args, function(data,response) {
      // parsed response body as js object 
      console.log(data, "data in client post");
});

and formData is a proper valid json what am doing wrong

updated here is the snapshot

I am a newby in Node js, after hit HubSpot api through node js by using node-rest-middleware am getting below kind of response. Why?

<Buffer 7b 22 76 69 64 22 3a 35 2c 22 63 61 6e 6f 6e 69 63 61 6c 2d 76 69 64 22 3a 35 2c 22 6d 65 72 67 65 64 2d 76 69 64 73 22 3a 5b 5d 2c 22 70 6f 72 74 61 ... >

Here is my snippet please take a look

var args = {
    data: formData,
    headers:{"Content-Type": "application/json"}
};

client.post(hubURL, args, function(data,response) {
      // parsed response body as js object 
      console.log(data, "data in client post");
});

and formData is a proper valid json what am doing wrong

updated here is the snapshot

Share Improve this question edited Aug 26, 2015 at 4:30 The Mechanic asked Aug 26, 2015 at 4:20 The MechanicThe Mechanic 2,3291 gold badge28 silver badges37 bronze badges 4
  • Could not find the middleware in npm. Try utf8 encoding the buffer. Or, just use npmjs./package/request – Swaraj Giri Commented Aug 26, 2015 at 4:23
  • @SwarajGiri unable to use request middleware. I haven't see how to hit rest api through request. here is the link npmjs./package/node-rest-client – The Mechanic Commented Aug 26, 2015 at 4:24
  • Start by converting the buffer to a string and see what's inside. That might give you a hint – Amit Commented Aug 26, 2015 at 4:29
  • updated my answer, this should work. – Mritunjay Commented Aug 26, 2015 at 4:33
Add a ment  | 

3 Answers 3

Reset to default 4

The data you are getting is a Buffer. Try converting it to string like bellow.

if(Buffer.isBuffer(data)){
    data = data.toString('utf8');
}
console.log(data);

This is data formatting issue, you are getting data in Buffer format and you want it in String format.

You can explicitly do the conversion.

You can use toString() of the Buffer, which will convert Buffer format into String format. Refer

var yourStringData = data.toString('utf8');

The Buffer should be converted to a String

client.post(baseUri + "tradingpartners/",args, function (data, response) {
    // parsed response body as js object
  console.log(data.toString('utf8'));
});
发布评论

评论列表(0)

  1. 暂无评论