Domanda

Quando si tenta di accorciare un legame con "#, e" il carattere ottengo un'eccezione. Esiste un modo per gestire questi caratteri correttamente?

Questo è un esempio di codice che funziona:

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

Se aggiungo ad esempio '&' o '% 25' alla stringa sarà un'eccezione:

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

La funzione getShortUrl da questo classe Java .

Grazie

È stato utile?

Soluzione

Questa libreria (la classe Java si collega a) non sfugge l'URL ... che è abbastanza terribile.

Estratto:

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

Si noti come urlToShorten non è sfuggito in alcun modo, forma o contenuto. Inclini ad attacchi di iniezione in stile, e in generale non funziona.

In ogni caso, è necessario sfuggire urlToShorten.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top