Skip to content

Instantly share code, notes, and snippets.

@alastair38
Last active April 19, 2018 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alastair38/9ea87f2a70f433cb6d18e7e5228e0a08 to your computer and use it in GitHub Desktop.
Save alastair38/9ea87f2a70f433cb6d18e7e5228e0a08 to your computer and use it in GitHub Desktop.
fetch("https:.....", { // url used is QA endpoint supplied (excluded here for security reasons)
method: "GET",
headers: {
"Authorization": "Basic c3ltcGxlY3RpY1BTWUNISUFUUlk6YnJpZ2h0Ymx1ZXN0YWdl" //encoded username:password
}
}).then(
function(response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' +
response.status);
return;
}
// Examine the text in the response
response.json().then(function(data) {
console.log(data);
});
}
)
.catch(function(err) {
console.log('Fetch Error :-S', err);
});
$URL='https:....'; // url used is QA endpoint supplied (excluded here for security reasons)
$headers = array(
'Authorization: Basic c3ltcGxlY3RpY1BTWUNISUFUUlk6YnJpZ2h0Ymx1ZXN0YWdl' //encoded username:password
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 60); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); // also tried with TRUE
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
if (!curl_errno($ch)) {
$info = curl_getinfo($ch);
print_r($info);
} else {
print curl_error($ch);
}
$result=curl_exec ($ch);
print($result);
curl_close ($ch);
$.ajax({
type: 'GET',
url: 'https:....', // url used is QA endpoint supplied (excluded here for security reasons)
headers: {
"Authorization": "Basic c3ltcGxlY3RpY1BTWUNISUFUUlk6YnJpZ2h0Ymx1ZXN0YWdl", //encoded username:password
},
success: function(data) {
/* handle data here */
console.log(data);
},
error: function(xhr, status) {
/* handle error here */
console.log(status);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment