[Mono-dev] [PATCH] Improve System.Net.WebClient's CreateUri(Uri address) query string handling

Gonzalo Paniagua Javier gonzalo.mono at gmail.com
Sat Mar 20 00:35:36 EDT 2010


On Fri, 2010-03-19 at 21:08 -0700, Jon Herron wrote:
> This patch fixes an issue I ran into when passing a Uri to WebClient's
> DownloadString method that contains a query string - CreateUri would
> re-append the query string to the end of the uri.  This makes
> CreateUri work similar to MakeUri.  I didn't see a great way to make a
> test for this, however for this sample app:
> 
> using System;
> using System.Net;
> 
> public class TestWebClientBug
> {
>   public static void Main(string[] args)
>   {
>     String url = "http://localhost/?var1=ok and more text also&var2=4&var3=caribou";
>     WebClient wc = new WebClient();
>     Uri uri = new Uri(url);
> 
>     wc.DownloadString(url);
>     wc.DownloadString(uri);
>   }
> }
> 
> In my access logs with mono 2.6.1 I see:
> 
> 127.0.0.1 - - [19/Mar/2010:19:50:11 -0400] "GET /?var1=ok%20and%20more%20text%20also&var2=4&var3=caribou HTTP/1.1" 200 3662
> 127.0.0.1 - - [19/Mar/2010:19:50:11 -0400] "GET /?var1=ok and more text also&var2=4&var3=caribou?var1=ok%20and%20more%20text%20also&var2=4&var3=caribou HTTP/1.1" 200 3662
> 
> With this patch applied to trunk:
> 
> 127.0.0.1 - - [19/Mar/2010:19:50:33 -0400] "GET /?var1=ok%20and%20more%20text%20also&var2=4&var3=caribou HTTP/1.1" 200 3662
> 127.0.0.1 - - [19/Mar/2010:19:50:33 -0400] "GET /?var1=ok%20and%20more%20text%20also&var2=4&var3=caribou HTTP/1.1" 200 3662

I'm afraid your patch might be hiding another issue: can you try your
URL + setting some values in wc.QueryString? What the resulting url in
that case?

-Gonzalo




More information about the Mono-devel-list mailing list