문제

When I try to shorten a link with "#,&" character I get an exception. Is there a way to handle these character properly?

This is a sample code that works:

String shortUrl = bitly.getShortUrl("http://z"); //Works

If I add for example '&' or '%25' to the string it will throw an exception:

String shortUrl = bitly.getShortUrl("http://z%26"); // Exception 
String shortUrl = bitly.getShortUrl("http://z&"); // Exception

The getShortUrl function from this Java class.

Thanks

도움이 되었습니까?

해결책

That library (the Java class you link to) doesn't escape the URL... that's pretty awful.

Excerpt:

private String getBitlyHttpResponseText(String urlToShorten) throws IOException {
  String uri = getBitlyUrl() + urlToShorten + bitlyAuth;
  HttpGet httpGet = new HttpGet(uri);
  ...

Notice how urlToShorten isn't escaped in any way, shape or form. Prone to injection-style attacks, and just generally doesn't work.

Anyway, you'll need to escape urlToShorten.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top