简体   繁体   English

转换后 API 代码以在 nodejs 中获取 API

[英]converting post API code to get API in nodejs

I am consuming below API using post.我正在使用帖子在 API 以下消费。 I have another API which I have to consume using get.我还有另一个 API 必须使用 get 来使用。 instead of request.post I used request.get it is giving 401 error.而不是 request.post 我使用 request.get 它给出了 401 错误。 I have to consume another API using GET with basic authentication.我必须使用带有基本身份验证的 GET 来使用另一个 API。 anybody can suggest changes for it.任何人都可以建议对其进行更改。

var request = require('request');
var url = 'http://localhost:3000/api/v1/login/'
var user = 'test35';
var pass = 'mypassword';
request.post(
  {
    uri: url,
    form: { username: user, password: pass }
  },
  function(err, httpResponse, body) {
    if (err) {
      return console.error('post failed:', err);
    }
    var json = JSON.parse(body);
    console.log('Post successful!  Server responded with:', body);
  }
);

Does the response of that post request an authentication token (for example an jwt)?该帖子的响应是否请求身份验证令牌(例如 jwt)? APIs usually return some key that you can use in further requests, for example, in your headers in an get request API 通常会返回一些您可以在进一步请求中使用的密钥,例如,在获取请求的标头中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM