Skip to content Skip to sidebar Skip to footer

Does Bitly Api Support Cors?

I saw in their documentation that CORS is supported. But my attempts to make request from JavaScript have no success. Requesting this URL: https://api-ssl.bitly.com/v3/shorten?long

Solution 1:

If anyone still having this issue. The reason this happen is because the option (preflight) response from bitly doesn't include 'Access-Control-Allow-Origin' header.

to get around this I used XMLHttpRequest which doesn't send preflight.

let xhr = newXMLHttpRequest();
let url = 'https://api-ssl.bitly.com/v3/shorten?longUrl=https://google.com/&access_token=token'
xhr.open('GET', url);
xhr.onreadystatechange = function() {
   if(xhr.readyState === 4) {
     if(xhr.status===200) {
         console.log(xhr.responseText)
     } else {
         console.log(xhr)
     }
   }
};
xhr.send();

It is actually mentioned in bitlly's documentation

Post a Comment for "Does Bitly Api Support Cors?"