title: Adding parameters to an HttpWebRequest
body: <p>This question has been asked a million times, and yet none of the responses work for me. The one I was most excited about was <a href="https://stackoverflow.com/questions/14698879/http-post-for-windows-phone-8">Http Post for Windows Phone 8</a> but because it requires delegates, it's not right for my code... the Postdata function is called from repositories, it would be nice to get a response straight from this function!</p>
  
  <p><strong>How do I add post parameters to this code? I've been trying to get it to work for a good 10 hours now.</strong></p>
  
  <pre><code>// Repository code
  
  string url = "/bla/bla/" + blaId + "/";
  Dictionary&lt;string, string&gt; postParams = new Dictionary&lt;string, string&gt;();
  postParams.Add("value", message);
  string response = await BlaDataContext.PostData(url, postParams);
  
  // ...
  
  public static async Task&lt;string&gt; PostData(string url, Dictionary&lt;String, String&gt; postParams)
  {
      HttpWebRequest request = WebRequest.CreateHttp(APIURL + url);
      request.ContentType = "application/x-www-form-urlencoded";
      request.Method = "POST";
      postParams.Add("oauth_token", Contract.AccessToken); // where do I add this to the request??
  
      try
      {
          HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();
  
          Debug.WriteLine(response.ContentType);
          Stream responseStream = response.GetResponseStream();
          string data;
          using (var reader = new StreamReader(responseStream))
          {
              data = reader.ReadToEnd();
          }
          responseStream.Close();
  
          return data;
      }
      catch (Exception e)
      {
          // whatever
      }
  }
  </code></pre>