以下是我尝试登录用户的代码。但它对我不起作用。
function test(url){
const authEncoded=base.encode("mobile_android:secret");
console.log(authEncoded)
const jbody={
'username':urlencode('b@p.com'),
'password':urlencode('123456'),
'client_id':urlencode('mobile_android'),
'client_secret':urlencode('secret'),
'grant_type':urlencode('password')
}
request({
url: url,
method: "POST",
headers: {
"Authorization": "Basic "+authEncoded,
"Content-Type":"application/x-www-form-urlencoded",
"Content-Length": Buffer.byteLength(JSON.stringify(jbody))
},
body: jbody,
json:true
}, function (error, response, body){
console.log(response);
console.log(error);
console.log(body)
});
}
当我运行上面的代码时,它给了我以下异常
D:\Node\node_modules\request\lib\querystring.js:43
return str.replace(/[!'()*]/g, function (c) {
^
TypeError: str.replace is not a function
at Querystring.rfc3986
(D:\Node\node_modules\request\lib\querystring.js:43:14)
at Request.json (D:\Node\node_modules\request\request.js:1293:30)
at Request.init (D:\Node\node_modules\request\request.js:406:10)
at new Request (D:\Node\node_modules\request\request.js:127:8)
at request (D:\Node\node_modules\request\index.js:53:10)
at test (D:\Node\testing.js:24:4)
at Object.<anonymous> (D:\Node\testing.js:42:1)
at Module._compile (internal/modules/cjs/loader.js:759:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
at Module.load (internal/modules/cjs/loader.js:628:32)
at Function.Module._load (internal/modules/cjs/loader.js:555:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:824:10)
at internal/main/run_main_module.js:17:11