我正在尝试使用一些用户名和密码使用Javascript调用 AwaazDe 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", "saurabh134741@nitp.ac.in");
xhttp.setRequestHeader("password", "12345");*/
xhttp.setRequestHeader("Authorization", authenticateUser("username","password"));
xhttp.send();
var response = JSON.parse(xhttp.responseText);
alert("No response");
/*}*/
请帮我解决这个问题。任何帮助将受到高度赞赏。
答案 0 :(得分:0)
它不起作用,因为https://awaaz.de:443/不允许跨域请求 跨源请求已阻止:同源策略禁止在https://awaaz.de/console/streams-api/groups/读取远程资源。 (原因:CORS标题'Access-Control-Allow-Origin'缺失