Search code examples
url-shortener

Can Bitly shorten percent symbol contained URL?


I have been trying to shorten URL contains % symbol to bitly shorten API:

Examples

My Original URL:

https://www.google.com?param=40%OFF

Doesn't work

https://api-ssl.bitly.com/v3/shorten?access_token=...&longUrl=https%3A%2F%2Fwww.google.com%3Fparam%3D40%25+OFF

When I try to eliminate the percent from URL, then encoded it again, it works:

https://api-ssl.bitly.com/v3/shorten?access_token=...&longUrl=https%3A%2F%2Fwww.google.com%3Fparam%3D40+OFF

I am not able to find Bitly doc states it does not able to shorten percent contained URL

Anyone has advise?


Solution

  • The URL you're passing to shorten isn't a syntactically valid URL. Perhaps you meant ...&longUrl=https%3A%2F%2Fwww.google.com%3Fparam%3D40%2525OFF, which when decoded gives longUrl the value https://www.google.com?param=40%25OFF, which when decoded gives param the value 40%OFF. Without the "extra" 25, decoding fails at the second step since O isn't a hexadecimal digit.