Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Status code 500, ReasonPhrase:'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent

I am creating a mobile app using xamarin forms. However, I get the following exception:

Status code 500, ReasonPhrase:'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent,

While trying to execute postAsync. I have no idea where it went wrong.

Here's the code that causes the exception:

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 < 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");
}
like image 382
GCK 1617 Avatar asked Oct 29 '22 16:10

GCK 1617


1 Answers

The error is on your web service. You should debug your web service and solve the problem there.

like image 198
FredyWenger Avatar answered Nov 15 '22 06:11

FredyWenger