我正在尝试拨打AwaazDe REST API使用Javascript使用一些用户名和密码。但它不起作用。这里是我的代码使用Javascript使用用户名和密码调用REST API?
function authenticateUser(user, password)
{
var token = user + ":" + password;
// Should i be encoding this value????? does it matter???
// Base64 Encoding -> btoa
var hash = btoa(token);
return "Basic " + hash;
}
/*function UserAction() {*/
/* alert("Searching!");*/
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "https://awaaz.de:443/console/streams-api/groups/", false);
xhttp.setRequestHeader("Content-type", "application/json");
/*xhttp.setRequestHeader("username", "[email protected]");
xhttp.setRequestHeader("password", "12345");*/
xhttp.setRequestHeader("Authorization", authenticateUser("username","password"));
xhttp.send();
var response = JSON.parse(xhttp.responseText);
alert("No response");
/*}*/
请帮我解决这个问题。任何帮助将不胜感激。
不工作是非常模糊的词在您得到可能帮助的任何错误方面具体 –
不工作意味着不使用使用REST API的GET方法获取内容。 –
@SaurabhSinha打开浏览器调试器(NET)控制台并检查更多信息。它会节省您的时间 –