I got an error from a PUT request.But i found it can work without the header option.
The request with a header options is like this:
'use strict';
var request = require("request");
request({
method: 'PUT',
uri: 'http://v2.openapi.ele.me/restaurant/62028381/order_mode/?consumer_key=0170804777&sig=bc8b56be4f9d33942eb22bd66ab1f2a49eea91f4×tamp=1465890208',
body: {
order_mode: 1
},
json: true,
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
},
}, (err, response, body) => {
console.log(body);
});
And the error is:
/Users/keller/xfxb/brownie/node_modules/request/lib/querystring.js:44
return str.replace(/[!'()*]/g, function (c) {
^
TypeError: str.replace is not a function
at Querystring.rfc3986 (/Users/keller/xfxb/brownie/node_modules/request/lib/querystring.js:44:14)
at Request.json (/Users/keller/xfxb/brownie/node_modules/request/request.js:1201:30)
at Request.init (/Users/keller/xfxb/brownie/node_modules/request/request.js:421:10)
at new Request (/Users/keller/xfxb/brownie/node_modules/request/request.js:142:8)
at request (/Users/keller/xfxb/brownie/node_modules/request/index.js:55:10)
Is there any problem with my headers option or is the problem from the module?
Try form
instead of body
form: {
order_mode: 1
},
I get the same error. its trying to string.replace on an object, when using Body, but the headers is set to FormData. So its a mixup of data types
set 'useQuerystring': false in reqOptions:
'use strict';
var request = require("request");
request({
method: 'PUT',
uri: 'http://v2.openapi.ele.me/restaurant/62028381/order_mode/?consumer_key=0170804777&sig=bc8b56be4f9d33942eb22bd66ab1f2a49eea91f4×tamp=1465890208',
body: {
order_mode: 1
},
json: true,
useQuerystring: false,
headers: {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
},
}, (err, response, body) => {
console.log(body);
});
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Try
form
instead ofbody