#2398 WebClient not allowing an ampersand in a query parameter

Jeremy Criquet Sun 8 Mar 2015

How would you format your uri for this:

http://www.imdb.com/find?q=Oru+Black+%26+White+Kudumbam&&s=tt&&exact=true

Notice the encoded ampersand as %26? If I do this:

`http://www.imdb.com/find?q=Oru Black \& White Kudumbam&&s=tt&&exact=true`

Then it won't give a valid response (like the browser does). When I do:

`http://www.imdb.com/find`.plusQuery( ["q":"Oru Black & White Kudumbam", "s":"tt", "exact":"true"] )

I then get the same URI as above.

Am I doing something wrong or is WebClient not working as intended?

SlimerDude Sun 8 Mar 2015

I find that Fantom URIs work very well - I think you're just forgetting to encode it:

uri := `http://www.imdb.com/find`.plusQuery( ["q":"Oru Black & White Kudumbam", "s":"tt", "exact":"true"] )
echo(uri.encode)
// --> http://www.imdb.com/find?s=tt&q=Oru+Black+%26+White+Kudumbam&exact=true

Constructing the URI using plusQuery() is the correct way. But note that a URI printed with toStr() prints it in the Fantom normalized form, whereas a URI printed with encode() prints it as required / used by a Browser.

Jeremy Criquet Thu 12 Mar 2015

Yeah, I tried that too. The WebClient takes a Uri, not a Str, and encode() returns a Str. Using toUri on that won't work either (I already tried that anyways by hardcoding the "encoded" uri into it). I'm pretty sure this is an issue with WebClient, not Uri as I've found Uri's to handle very well in all other cases.

SlimerDude Thu 12 Mar 2015

What does your WebClient code look like? How do you know it's not working?

You could try using Butter in place of WebClient but the HTTP connection code is very similar - so you'd probably get the same result.

brian Thu 12 Mar 2015

If you look at WebClient its actually not a lot of code. It just uses the encoded version of your URI:

// request uri is absolute if proxy, relative otherwise
reqPath := (usingProxy ? reqUri : reqUri.relToAuth).encode

Login or Signup to reply.