title: WebRequest converting URL to Encoded in Xamarin (MonoTouch)
body: <p>I am working on a API based App in Xamarin using HttpWebRequest class. I have to send request to URL</p>
  
  <pre><code>http://example.com/APIRequest/Request?Parts=33333|N|2014|ABCD
  </code></pre>
  
  <p>But when I see this request in Fiddler it shows me URL like</p>
  
  <pre><code>http://example.com/APIRequest/Request?Parts=33333%7CN%7C2014%7CABCD
  </code></pre>
  
  <p>Now the problem is this encoded URL is not getting understood by server and its returning errors, which is beyond my control.</p>
  
  <p>Earlier in .NET2.0 C# Application I was using</p>
  
  <pre><code>Uri url = new Uri(rawurl, true);
  </code></pre>
  
  <p>But the second parameter has been deprecated in .NET 4.0 MonoTouch available on Xamarin so its giving error or simply not doing anything.</p>
  
  <p>I have  tried all possible ways like UrlDecode, htmldecode, double decode or even Java UrlDecode but nothing has worked and always shows encoded URL in Fiddler.</p>
  
  <p>Please suggest how to overcome this problem or any alternate to new Uri(url-string, true) the old function.</p>
  
  <h2>UPDATE:</h2>
  
  <p>After spending hours n hours probably I have found the culprit. The problem is </p>
  
  <p>When I use "new Uri(url, true)", it sends unescaped URL containing | (pipe) to WebRequest.Create but if I remove "true" it sends encoded URL, which produces result but unfortunately server doesn't understand, so I get error.</p>
  
  <pre><code>Uri ourUri = new Uri(url, true);
  myHttpWebResponse1 = (System.Net.HttpWebResponse)request.GetResponse();
  </code></pre>
  
  <p>But it may be a bug that request.GetResponse() Stops working without throwing any exception and process hangs if I use | (pipe) in URL.</p>
  
  <p>Any possible solution to that?</p>
  
  <p>My complete function is given below (modified with hardcoded URL)</p>
  
  <pre><code>public static string getURLCustom(string GETurl, string GETreferal)
  {
      GETurl = "http://example.com/?req=111111|wwww|N|2014|asdwer4";
      GETreferal = "";
      Uri ourUri = new Uri(GETurl.Trim(), true);
      HttpWebRequest request = (HttpWebRequest)(WebRequest.Create(ourUri));
      request.Method = "GET";
      request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)";
      request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
      request.KeepAlive = true;
      request.CookieContainer = loginCookie; //stored after login
      request.ContentType = "application/x-www-form-urlencoded";
      request.Referer = GETreferal;
      request.AllowAutoRedirect = true;
      HttpWebResponse myHttpWebResponse1 = default(HttpWebResponse);
      myHttpWebResponse1 = (System.Net.HttpWebResponse)request.GetResponse();
      StreamReader postreqreader1 = new StreamReader(myHttpWebResponse1.GetResponseStream());
      return postreqreader1.ReadToEnd();
  }
  </code></pre>
  
  <p>And yes this code works perfectly in .NET 2.0 Windows Application but not on Xamarin Mono-Touch App.</p>