How can I consume a web service with Play Framework 2 when the url has a colon in it?

988 Views Asked by At

This url works fine when I try it in my browser:

https://username:[email protected]/api/Listings?$top=3

But when I run this code:

Promise<WS.Response> page = WS.url("https://username:[email protected]/api/Listings?$top=3").get();

I get this exception:

IllegalArgumentException: Illegal URL: https://username:[email protected]/api/Listings

I discovered that if I remove the colon from between username and password it doesn't throw an exception.

So I tried escaping the colon like this and got the same exception:

Promise<WS.Response> page = WS.url("https://username%[email protected]/api/Listings?$top=3").get();

How can I get around this issue?

1

There are 1 best solutions below

1
On BEST ANSWER

I haven't tested, but it should work this way:

WSRequestHolder requestHolder = WS.url("https://api.prosper.com/api/Listings?$top=3");
requestHolder.setAuth("username", "password");
Promise<Response> promise = requestHolder.get();