向外部Rest API发送请求时取消授权401错误

时间:2019-07-02 14:41:07

标签: javascript rest xmlhttprequest http-authentication dojo.xhrget

我想从外部api获取pdf数据,并且该api需要身份验证。我在标题中设置了授权,但仍然收到“未授权(401)”响应。

var xhrArgs = {
                    url: 'my_url',
                    headers: {
                        "Authorization": "Basic Y29tbWVyY2VBcHA6R3JAeWJAckFwcHMu",
                        "accept": "application/pdf"

                    },
                    load: function(data){
                      // Replace newlines with nice HTML tags.
                      console.info(data);
                    },
                    error: function(error){
                      console.info("An unexpected error occurred: " + error);
                    }
                  }

          // Call the asynchronous xhrGet
          var deferred = dojo.xhrGet(xhrArgs);

0 个答案:

没有答案