title: Building URI with the http client API
body: <p>I have to build a URI address with dynamic query strings and looking for a comfortable way to build them via code. </p>
  
  <p>I browsed the System.Net.Http assembly but doesn't found a class or method for this case. Does this API not provide this?  My search results here at StackOverflow uses the HttpUtility class from the System.Web, but I don't want to reference any ASP.Net components in my class library.</p>
  
  <p>I need a URI like this : <a href="http://www.myBase.com/get?a=1&amp;b=c" rel="nofollow">http://www.myBase.com/get?a=1&amp;b=c</a>.</p>
  
  <p>Thanks in advance for helping!</p>
  
  <p>Update (2013/9/8):</p>
  
  <p>My solution was to create a URI builder that uses System.Net.WebUtilitiy class for encoding the values (The imported NuGet package unfortunately didn't provide a strong name key).
  Here's my code :</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Helper class for creating a URI with query string parameter.
  /// &lt;/summary&gt;
  internal class UrlBuilder
  {
      private StringBuilder UrlStringBuilder { get; set; }
      private bool FirstParameter { get; set; }
  
      /// &lt;summary&gt;
      /// Creates an instance of the UriBuilder
      /// &lt;/summary&gt;
      /// &lt;param name="baseUrl"&gt;the base address (e.g: http://localhost:12345)&lt;/param&gt;
      public UrlBuilder(string baseUrl)
      {
          UrlStringBuilder = new StringBuilder(baseUrl);
          FirstParameter = true;
      }
  
      /// &lt;summary&gt;
      /// Adds a new parameter to the URI
      /// &lt;/summary&gt;
      /// &lt;param name="key"&gt;the key &lt;/param&gt;
      /// &lt;param name="value"&gt;the value&lt;/param&gt;
      /// &lt;remarks&gt;
      /// The value will be converted to a url valid coding.
      /// &lt;/remarks&gt;
      public void AddParameter(string key, string value)
      {
          string urlEncodeValue = WebUtility.UrlEncode(value);
  
          if (FirstParameter)
          {
              UrlStringBuilder.AppendFormat("?{0}={1}", key, urlEncodeValue);
              FirstParameter = false;
          }
          else
          {
              UrlStringBuilder.AppendFormat("&amp;{0}={1}", key, urlEncodeValue);
          }
  
      }
  
      /// &lt;summary&gt;
      /// Gets the URI with all previously added paraemter
      /// &lt;/summary&gt;
      /// &lt;returns&gt;the complete URI as a string&lt;/returns&gt;
      public string GetUrl()
      {
          return UrlStringBuilder.ToString();
      }
  }
  </code></pre>
  
  <p>Hope this helps somebody here at StackOverflow. My request is working.</p>
  
  <p>Björn</p>