title: How to post data on JSON web services in Windows Phone 8
body: <p>I want to post data on JSON web services for login credentials for user.</p>
  
  <p>I use the below code to post data on JSON web service.</p>
  
  <pre><code>private void Button_Click_1(object sender, RoutedEventArgs e)
      {
          // Create a new HttpWebRequest object.
          HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://test/TestService/Service.svc/json/Login");
  
          request.ContentType = "application/json";
          //request.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; Touch)";
         // request.CookieContainer = cookie;
  
          // Set the Method property to 'POST' to post data to the URI.
          request.Method = "POST";
  
          // start the asynchronous operation
          request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request);
  
      }
  private void GetRequestStreamCallback(IAsyncResult asynchronousResult)
      {
              HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
  
              // End the operation
              Stream postStream = request.EndGetRequestStream(asynchronousResult);
  
              //postData value
              string postData = "{'userid': '" + textUserid.Text + "','password':'" + textPassword.Text + "'}";
  
              // Convert the string into a byte array. 
              byte[] byteArray = Encoding.UTF8.GetBytes(postData);
  
              // Write to the request stream.
              postStream.Write(byteArray, 0, postData.Length);
              postStream.Close();
  
              // Start the asynchronous operation to get the response
              request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
  
      }
  private void GetResponseCallback(IAsyncResult asynchronousResult)
      {
  
              HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
              // End the operation
  
              HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
  
              Stream streamResponse = response.GetResponseStream();
  
              StreamReader streamRead = new StreamReader(streamResponse);
              string read = streamRead.ReadToEnd();
  
              //respond from httpRequest
              //TextBox.Text = read;
              MessageBox.Show("Your Response: " + read);
              // Close the stream object
              streamResponse.Close();
              streamRead.Close();
              response.Close();
      } 
  </code></pre>
  
  <p>and I import following namespace in my code</p>
  
  <pre><code>using System.Net;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Navigation;
  using Microsoft.Phone.Controls;
  using Microsoft.Phone.Shell;
  using System.Text;
  </code></pre>
  
  <p>I am calling Button_Click_1 method clicking login button from my Windows Phone simulator.</p>
  
  <p>But I am getting this error:</p>
  
  <pre><code>Error   1   'System.Net.WebRequest' does not contain a definition for 'GetRequestStream' and no extension method 'GetRequestStream' accepting a first argument of type 'System.Net.WebRequest' could be found (are you missing a using directive or an assembly reference?) E:\Users\maan\Documents\Visual Studio 2012\Projects\TestWebservice\TestWebservice\MainPage.xaml.cs  99  39  TestWebservice
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Error   2   'System.Net.WebRequest' does not contain a definition for 'GetResponse' and no extension method 'GetResponse' accepting a first argument of type 'System.Net.WebRequest' could be found (are you missing a using directive or an assembly reference?)   E:\Users\maan\Documents\Visual Studio 2012\Projects\TestWebservice\TestWebservice\MainPage.xaml.cs  106 39  TestWebservice
  </code></pre>
  
  <p>Please help me I am new to developing Windows mobile application.</p>