views:

151

answers:

2

I am trying to use DefaultHttpClient and HttpGet to make a request to a web service. Unfortunately the web service URL contains illegal characters such as { (ex: domain.com/service/{username}). It's obvious that the web service naming isn't well written but I can't change it.

When I do HttpGet(url), I get that I have an illegal character in the url (that is { and }). If I encode the URL before that, there is no error but the request goes to a different URL where there is nothing.

The url, although has illegal characters, works from the browser but the HttpGet implementation doesn't let me use it. What should I do or use instead to avoid this problem?

+1  A: 

http://java.sun.com/javase/6/docs/api/java/net/URLEncoder.html

Specifically:

String safeUrl = URLEncoder.encode("domain.com/service/{username}", "UTF-8");
Mike
Hmm. As I said in the question, I have tried encoding (exact line as yours) but it didn't work. I retried now and Success! Thanks.
kaciula
The first time I tried it and failed was because the connection timeout expired.
kaciula
A: 

Have you tried using %7B and %7D, like so: domain.com/service/%7Busername%7D. Or is that what you mean by encoding.

sblundy