search

Home  >  Q&A  >  body text

javascript - Nodejs calls qiniu's third-party resource capture and returns 401 bad token. Why

1.nodejs calls qiniu's third-party resource capture and returns 401 bad token, why
2. The code is as follows:
var encode_url = qiniu.util.urlsafeBase64Encode(imageUrl);
var encode_bucket = qiniu.util.urlsafeBase64Encode(bucket);
console.log(encode_bucket);
console.log(encode_url);

var post_url = 'http://iovip.qbox.me/fetch/' encode_url '/to/' encode_bucket;
console.log(url.parse(post_url).path);
var author = qiniu.util.generateAccessToken(imageUrl);
console.log('post_url = %s.nauthor = %s.', post_url, author);

let rsOptions = {

method: 'POST',
uri: post_url,
header: {
  host: 'iovip.qbox.me',
  authoration: author,
  'content-type': 'application/x-www-form-urlencoded'
},

};
return rp(rsOptions)

.then(function (rsJson) {
  if(rJson.status != 'ok') {
    return Promise.reject(errorCode.imgServiceFail);
  }
  var data = rsJson.data;
  console.log(data);
  return Promise.resolve(data);
});

2. The error is as shown in the picture:

3. Refer to http://www.cnblogs.com/weiniu..., but it is not resolved;
I read this post, the problem is the same but the result is the same. . . . Please give me the answer. Thank you very much! ! ! !

阿神阿神2750 days ago959

reply all(1)I'll reply

  • 阿神

    阿神2017-06-26 10:55:04

    Hahaha, no one answered. I was also drunk. I complained about qn. Originally, this question required a work order, but every time I scanned the code on WeChat, I was asked to scan it again. I was confused, and then I could only wander around on the Internet. . In fact, my code is correct, but my request assembly was wrong.
    When I first started, I read this article /q/10...; but I didn’t know where I went wrong. I kept wondering why the bad token was. The whole process was only 3 lines of code. I was dissatisfied, and then I glanced back and realized that I had made a grammatical mistake. 2333333!
    let rsOptions = {

    method: 'POST',
    uri: post_url,
    headers: {
      host: 'iovip.qbox.me',
      authorization: author,
      'content-type': 'application/x-www-form-urlencoded'
    },

    };

    reply
    0
  • Cancelreply