javascript - Die von js beim Schreiben einer Abrufanforderung zurückgegebene Fehlermeldung ist nicht autorisiert. Liegt ein Pfadspleißfehler vor oder ist die Ajax-Anfrage falsch geschrieben?
ringa_lee
ringa_lee 2017-05-16 13:28:01
0
1
489

//Anmeldeinformationen verwalten
function genManageToken(accessKey, SecretKey, pathAndQuery, body) {

var str = pathAndQuery + body;
var hash = CryptoJS.HmacSHA1(str, secretKey);
var encodedSign = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(hash));
return accessKey + ":" + encodedSign;

}
var fetchImg = function(picUrl) {

// 通过fetch进行远程图片抓取 
var accessKey = "AK";
var secretKey = "SK";
var srcUrl = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(picUrl));
var bucket = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse("cloudimg"+":"+(new Date()).getTime()+".jpg"));
var path = "/fetch/" + srcUrl + "/to/" + bucket;
var fetchUrl = "http://iovip.qbox.me" + path;
mui.ajax(fetchUrl, {
    dataType: 'json', //服务器返回json格式数据
    type: 'post', //HTTP请求类型
    timeout: 10000, //超时时间设置为10秒;
    headers: {
        'Content-Type': "application/json",
        'Authorization': "QBox " + genManageToken(accessKey, secretKey, path, "")
    },
    success: function(data) {
        //服务器返回响应,根据响应结果,分析是否登录成功;
        data = JSON.stringify(data);
        data = eval("(" + data + ")");
        //输出响应成功key值
        console.log(data['key']);
    },
    error: function(xhr, type, errorThrown) {
        //异常处理;
        console.log(errorThrown);
    }

});

}
//Fügen Sie die entsprechende js-Aufruffunktion in die Seite ein
fetchImg("https://www.baidu.com/img/bd_logo1.png");

ringa_lee
ringa_lee

ringa_lee

Antworte allen(1)
伊谢尔伦

编码问题已解决

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!