loopback icon indicating copy to clipboard operation
loopback copied to clipboard

body is null when rest builder invoke..

Open penzhan8451 opened this issue 11 years ago • 3 comments

var testdata = { name: 'Kobe', age: '38' }; var tostr = JSON.stringify(testdata); var access_token = 'xxxxxxx';

var restbuilder = require("loopback-connector-rest"); var builder = new restbuilder('POST','https:///test2.json') .header({"Accept": "application/json","Content-Type": "application/json","Authorization": "Bearer " + access_token,"Content-Length": tostr.length}) .body(tostr);

builder.invoke(processResponse);

when builder invoke, I found the body is null by debug, who knows what is wrong? Thanks.

penzhan8451 avatar May 18 '15 02:05 penzhan8451

Since you have the Content-Type set to application/json, the body should be a json object without stringify.

raymondfeng avatar May 18 '15 22:05 raymondfeng

Hi raymondfeng, thanks very much! I will try it.

penzhan8451 avatar May 19 '15 05:05 penzhan8451

Yes, It works. Thanks.

penzhan8451 avatar May 19 '15 23:05 penzhan8451