最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

我如何使用Node和node

IT培训 admin 6浏览 0评论

我如何使用Node和node

我正在尝试从文档(,)复制示例POST请求。如何在节点中编码此curl请求?

$ curl -u user:password localhost:8080/oauth/token -d grant_type=client_credentials
{"access_token":"c6b53866-b38a-41f9-878c-87bb280ca9d8","token_type":"bearer","expires_in":43199,"scope":"write"}

我有这个

var oauth = {
    data: { grant_type: "client_credentials" },
    headers: { "Content-Type": "application/json" }
};
var options_auth = { user: "user", password: "password" };
var client = new Client(options_auth);

client.post("http://127.0.0.1:8080/oauth/token", oauth, function (data, response) {
    // parsed response body as js object
    console.log(data);

但是它给我一个错误

[2019-10-15T00:40:23.780Z] { error: 'invalid_request', error_description: 'Missing grant type' }

OAuth服务器是值得的Spring Boot。

回答如下:

我必须更改标题值:

    headers: { "Content-Type": "application/x-www-form-urlencoded" }

现在它给了我访问令牌:

[2019-10-15T00:58:15.354Z] {                           
  access_token: 'c6b53866-b38a-41f9-878c-87bb280ca9d8',
  token_type: 'bearer',                                
  expires_in: 41873,                                   
  scope: 'write'                                       
}                                                      

我如何使用Node和node

我正在尝试从文档(,)复制示例POST请求。如何在节点中编码此curl请求?

$ curl -u user:password localhost:8080/oauth/token -d grant_type=client_credentials
{"access_token":"c6b53866-b38a-41f9-878c-87bb280ca9d8","token_type":"bearer","expires_in":43199,"scope":"write"}

我有这个

var oauth = {
    data: { grant_type: "client_credentials" },
    headers: { "Content-Type": "application/json" }
};
var options_auth = { user: "user", password: "password" };
var client = new Client(options_auth);

client.post("http://127.0.0.1:8080/oauth/token", oauth, function (data, response) {
    // parsed response body as js object
    console.log(data);

但是它给我一个错误

[2019-10-15T00:40:23.780Z] { error: 'invalid_request', error_description: 'Missing grant type' }

OAuth服务器是值得的Spring Boot。

回答如下:

我必须更改标题值:

    headers: { "Content-Type": "application/x-www-form-urlencoded" }

现在它给了我访问令牌:

[2019-10-15T00:58:15.354Z] {                           
  access_token: 'c6b53866-b38a-41f9-878c-87bb280ca9d8',
  token_type: 'bearer',                                
  expires_in: 41873,                                   
  scope: 'write'                                       
}                                                      

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论