title: Status code 500, ReasonPhrase:'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent
body: <p>I am creating a mobile app using xamarin forms. However, I get the following exception:</p>
  
  <blockquote>
    <p>Status code 500, ReasonPhrase:'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent,</p>
  </blockquote>
  
  <p>While trying to execute <code>postAsync</code>. I have no idea where it went wrong.</p>
  
  <p>Here's the code that causes the exception:</p>
  
  <pre><code>private async void btnCheckout_OnClicked(object sender, EventArgs e)
  {
      ConstantCS constant = new ConstantCS();
      var client = new HttpClient();
      client.BaseAddress = new Uri(constant.URLBaseAddress);
      //Store persive data locally 
      int MyOrdersID_ = int.Parse(Application.Current.Properties["MyOrdersID"].ToString());
  
      for (int i = 0; i &lt; orderItemList.Count; i++)
      {
          //string postdataJson = JsonConvert.SerializeObject(new { UserID = nric.Text.Trim(), Password = pin.Text.Trim() });
          string postJson = JsonConvert.SerializeObject(new { orderID = MyOrdersID_, itemID = orderItemList[i].Item_Id, itemName = orderItemList[i].orderItem_Name, orderQty = orderItemList[i].orderItem_Quantity, itemRequest = orderItemList[i].orderItem_SpecialReq, specialRequest = orderItemList[i].orderItem_OtherReq , itemPrice = orderItemList[i].orderItem_IndividualPrice});
          var content = new StringContent(postJson, Encoding.UTF8, "application/json");
          //HttpResponseMessage orderItemResponse = await client.PostAsync("WebServices/Orders.svc/CreateOrderItems", content);
          HttpResponseMessage orderItemResponse = new HttpResponseMessage();
          orderItemResponse = client.PostAsync("WebServices/Orders.svc/CreateOrderItems", content).Result;
  
          if (orderItemResponse.IsSuccessStatusCode)
          {
              await DisplayAlert("Success", "Order item response = " + orderItemResponse.ToString(), "OK");
          }
          else
          {
              await DisplayAlert("Failed", "Order item response = " + orderItemResponse.ToString(), "OK");
          }
  
          //var result = await response.Content.ReadAsStringAsync();
      }
      DateTime now = DateTime.Now;
      string postOrderJson = JsonConvert.SerializeObject(new { custID = 1, orderDateTime = now, orderID = MyOrdersID_, orderTotalPrice = totalCost });
      var OrderContent = new StringContent(postOrderJson, Encoding.UTF8, "application/json");
      HttpResponseMessage orderResponse = await client.PostAsync("WebServices/Orders.svc/CreateOrder", OrderContent);
      if (orderResponse.IsSuccessStatusCode)
      {
          await DisplayAlert("Success", "Order Response = " + orderResponse.ToString(), "OK");
      }
      else
      {
          await DisplayAlert("Failed", "Order Response = " + orderResponse.ToString(), "OK");
      }
      await Navigation.PushModalAsync(new MasterDetailPageFood());
      //Display an alert and then go back to the first page
      await DisplayAlert("Thank you for your order", "Your Order will be made shortly", "OK");
  }
  </code></pre>