Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put request throws error with headers option #2245

Closed
keller35 opened this issue Jun 15, 2016 · 4 comments
Closed

Put request throws error with headers option #2245

keller35 opened this issue Jun 15, 2016 · 4 comments
Labels

Comments

@keller35
Copy link

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&timestamp=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?

@laggingreflex
Copy link

Try form instead of body

form: {
  order_mode: 1
},

@IAMtheIAM
Copy link

IAMtheIAM commented Oct 20, 2017

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

@PashaTkachuk
Copy link

PashaTkachuk commented Mar 13, 2018

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&timestamp=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);
});

@stale
Copy link

stale bot commented Mar 13, 2019

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.

@stale stale bot added the stale label Mar 13, 2019
@stale stale bot closed this as completed Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants