I keep encountering an error message after clicking the button:
"POST 401 (Unauthorized)"
Check out my code below:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<button onclick="makePostCall()">Click me</button>
<script>
makePostCall = function() {
var username = "c0ae64ef-410a-4f74-b875-ef52dee90686";
var password = "9K2q4byngzo7";
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://watson-api-explorer.mybluemix.net/dialog/api/v1/dialogs/c8e08780-b08b-4cdb-8b8c-ea118863fcd1/conversation', true);
//xhr.withCredentials = true;
xhr.setRequestHeader('Access-Control-Allow-Origin', 'http://localhost:80');
xhr.setRequestHeader('Access-Control-Allow-Credentials', '*');
xhr.setRequestHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
xhr.setRequestHeader('Access-Control-Allow-Headers', 'Content-Type', 'application/json', 'Authorization');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.setRequestHeader('Authorization', 'Basic ' + btoa(username + " " + password));
xhr.send('{"query":{"match_all":{}}}');
}
</script>
</body>
</html>