-
Notifications
You must be signed in to change notification settings - Fork 73
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
not able to do x-www-unencoded body #136
Comments
maybe i jumped the gun on this. |
You could use such a http app: var q = require('q'),
qs = require('qs'),
apps = require('q-ui/http-apps');
function HandleUrlEncodedRequests(app) {
return function(req, res) {
return processUrlEncodedBody(req)
.catch(function(err) {
// TODO: should be 500 in case of syntax or any other error in processUrlEncodedBody() code
return statusResponse(req, 400, err.stack || err);
})
.then(function(req) {
return app(req, res);
});
}
}
function processUrlEncodedBody(obj) {
return q(obj)
.then(function(obj) {
var contentType = obj.headers['content-type'];
if (contentType && contentType.indexOf('x-www-form-urlencoded') > -1) {
return obj.body.read()
.then(function(body) {
obj.data = qs.parse(body.toString());
return obj;
});
}
return obj;
});
}
function statusResponse(req, status, addendum) {
return q.reject(apps.responseForStatus(req, status, req.method + ' ' + req.path + (addendum ? '\n' + addendum : '')));
} |
@arikon wow. thanks for your comment. |
This does indeed seem like a reasonable app to be included. |
tested an API with postman, and tried to emulate the successful call i could make with it.
set headers to
{"Content-Type": "application/x-www-form-urlencoded"}
set body to
[string that worked with postman in x-www... mode]
this is on https mode as well.
i can't get this type of request to work.
switched to request-promise lib and my request works fine using the
{form: }
optionThe text was updated successfully, but these errors were encountered: