ForbesLindesay / sync-request

Make synchronous web requests with cross platform support.
MIT License
326 stars 49 forks source link

try to make application/x-www-form-urlencoded Request but getting failed #104

Closed Himanshu44ec06 closed 6 years ago

Himanshu44ec06 commented 6 years ago

Hi, I am trying to make "application/x-www-form-urlencoded" Code is below

    var request = require("sync-request");
    var  FormData  =  request.FormData;
    var data = new FormData();
    data.append('grant_type', 'password');
    data.append('username', 'Administrator');
    data.append('client_id', 'b7d32cdd049d436bbbd314d8d7140861');
    data.append('password', '1');

    var  tokenRequestOptions = {
        headers: { 'content-type': 'application/x-www-form-urlencoded' },
        form: data
        };

    var result  =  request('post','https://qa2016-pp.sotiqa.com/sotiassist/account/oauth2/token',tokenRequestOptions);

This is Working fine when using NPM request

Please Help

ForbesLindesay commented 6 years ago

looks like it should work fine to me. you haven't really given me anything specific about what's not working though. Are you running this in a browser, or on node.js? What do you mean by "NPM request"? What exactly is the error/stack trace you get out of this?

Himanshu44ec06 commented 6 years ago

Are you running this in a browser, or on node.js? -- NODE JS What do you mean by "NPM request"? -- REQUEST package

ForbesLindesay commented 6 years ago

I don't know at a glance why this isn't working. You shouldn't need to specify the content-type header as that should happen automatically, but without you posting some info about what is actually going wrong, it's really hard to diagnose anything.