You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, if a json object is sent as data, it will url-encode the object.
If the server expects JSON, this will kill the request.
Reqwest includes the option to 'processData = false' within the request, but this leaves a JSON object being sent as [object Object].
This should be especially true of the contentType property is set to application/json, otherwise why would we send a url-encoded value if we are telling it to send json?
It would be nice to add an option to stringify a json object instead of url-encoding it, or otherwise auto-detect the application/json contentType and stringify the json object.
I added this in the code (without the option, just an object and contentType check),
in reqwest.js, line 203 inside getRequest():
function getRequest(fn, err) {
var o = this.o
, method = (o['method'] || 'GET').toUpperCase()
, url = typeof o === 'string' ? o : o['url']
// convert non-string objects to query-string form unless o['processData'] is false
, data = (o['processData'] !== false && o['data'] && typeof o['data'] !== 'string')
? (typeof o['data'] == 'object' && o['contentType'] == 'application/json') ? JSON.stringify(o['data']) : reqwest.toQueryString(o['data'])
: (o['data'] || null)
, http
, sendWait = false
...
If anyone doesn't see an objection to this, I'll add it as a pull request.
The text was updated successfully, but these errors were encountered:
rw3iss
changed the title
Suggestion: add JSON.stringify to post if data is a JSON object
Suggestion: add JSON.stringify to post if data is a JSON object and contentType is 'application/json'
Sep 29, 2016
mockdeep
added a commit
to mockdeep/questlog
that referenced
this issue
Jul 9, 2017
Currently, if a json object is sent as data, it will url-encode the object.
If the server expects JSON, this will kill the request.
Reqwest includes the option to 'processData = false' within the request, but this leaves a JSON object being sent as [object Object].
This should be especially true of the contentType property is set to application/json, otherwise why would we send a url-encoded value if we are telling it to send json?
It would be nice to add an option to stringify a json object instead of url-encoding it, or otherwise auto-detect the application/json contentType and stringify the json object.
I added this in the code (without the option, just an object and contentType check),
in reqwest.js, line 203 inside getRequest():
If anyone doesn't see an objection to this, I'll add it as a pull request.
The text was updated successfully, but these errors were encountered: