Skip to content

Can't asign content-type on POST #58

Description

@megamauricio009

Hi guys i'm trying to get a token from a service but it said's "error":"invalid_request","error_description":"Missing grant type
i was searching about this error and the solution is changing the content-type to "application/x-www-form-urlencoded" cause it can be sended by JSON. but it doesn't work, my code is this

`
var json = JSON.parse(JSON.stringify(jsonResp))

var body = decryptBody(req.body);
body = body.replace(/\0/g, '')
body = JSON.parse(body)
var auth = {grant_type:"password", username: "pass" , password: "usr" }
if(!isValidProtocol(body)){
//console.log(body)
json.error = true,
json.desc = 'invalid protocol'
res.statusCode = 202;
res.json(encryptBody(json));
}

requestify.request( "http://localhost:7070" + '/oauth/token',{
method: "POST",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
dataType: 'form-url-encoded',
auth: auth
})
.then(function(response) {
json.data = response.getBody();
res.json(encryptBody(json));
}).catch(function(err){
console.log('ERROR:')
console.log(err)
//console.log(body.data)
console.log(auth)
json.error = true,
json.desc = 'invalid login params'
res.statusCode = 202;
res.json(encryptBody(json));
});`

and the result

ERROR: Response { code: 400, headers: { 'x-content-type-options': 'nosniff', 'x-xss-protection': '1; mode=block', 'cache-control': 'no-cache, no-store, max-age=0, must-revalidate', pragma: 'no-cache', expires: '0', 'x-frame-options': 'DENY', 'content-type': 'application/json;charset=UTF-8', 'transfer-encoding': 'chunked', date: 'Tue, 20 Jun 2017 19:31:43 GMT', connection: 'close' }, body: '{"error":"invalid_request","error_description":"Missing grant type"}' }
Waitng for the answer, THANK YOU..

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions