title: HTTP POST method fails
body: <p>I am a beginner for using WebRequest in C# and I am trying to using POST method to check my orders in Apple Online Store (<a href="https://secure2.store.apple.com/order/list" rel="nofollow">https://secure2.store.apple.com/order/list</a>).</p>
  
  <p>I want to check a single order and found that I should use POST Method with Parameters: orderLookup-order-number(Order No) and orderLookup-order-user-info(My Apple Account).</p>
  
  <p>I have tried to post these 2 parameters to <a href="https://secure1.store.apple.com/us/shop/order/json/single" rel="nofollow">https://secure1.store.apple.com/us/shop/order/json/single</a> on <a href="https://www.hurl.it/" rel="nofollow">https://www.hurl.it/</a> by:</p>
  
  <p>POST TO: <a href="https://secure1.store.apple.com/us/shop/order/json/single" rel="nofollow">https://secure1.store.apple.com/us/shop/order/json/single</a> </p>
  
  <p>parameter1: orderLookup-order-number value: [Order No]</p>
  
  <p>parameter2: orderLookup-order-user-info value: [Apple ID]</p>
  
  <p>and successfully got a return. However when I do it in C#, I fail. Can anyone point out my mistakes please? My function is as follow.</p>
  
  <pre><code>bool TryPostMethodToGetHtmlText(string orderNo, string accountNo, out string htmlText)
  {
      HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://secure1.store.apple.com/us/shop/order/json/single");
      request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0";
      request.Method = "POST";
      request.ContentType = "application/x-www-form-urlencoded";
      var postData = "orderLookup-order-number=" + orderNo;
          postData += "&amp;orderLookup-order-user-info=";
          postData += HttpUtility.UrlEncode(accountNo);
      byte[] postBytes = Encoding.ASCII.GetBytes(postData);
      request.ContentLength = postBytes.Length;
      using (Stream st = request.GetRequestStream())
      {
          st.Write(postBytes, 0, postBytes.Length);
      }
  
      HttpWebResponse response = (HttpWebResponse)request.GetResponse();
      if (response.StatusCode == HttpStatusCode.OK)
      {
          Stream receiveStream = response.GetResponseStream();
          StreamReader readStream = null;
  
          if (response.CharacterSet == null)
          {
              readStream = new StreamReader(receiveStream);
          }
          else
          {
              readStream = new StreamReader(receiveStream, Encoding.GetEncoding(65001));
          }
          htmlText = readStream.ReadToEnd();
          response.Close();
          readStream.Close();
          return true;
      }
      htmlText = string.Empty;
      return false;
  }
  </code></pre>
  
  <p>I got a 503 error when I wanted to get the HttpWebResponse. Thank you.</p>