How to solve Newtonsoft.Json.JsonReaderException:

MonaMona Member

I am adding some data to API. But I am getting an error Newtonsoft.Json.JsonReaderException: ..
While debugging in response variable I am getting {StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Cache-Control: no-cache, private
Connection: close
Content-Type: text/html; charset=UTF-8
}}
As i am getting response in html format instead of json . I am unable to deserialize....Any suggestion plz.. where I am doing wrong?

public class StatusView
{
public string status { get; set; }
}

class AddBillFun
{
    public async static Task<StatusView> AddBillData(string transaction_date1, string billing_date1, string vehicle_id1, string customer_id1, string fuel_id1
                                               , string fuel_unit_id1, string fuel_price_id1, string price_per_unit1, string quantity1, string amount1
                                               , string recieved_amount1, string advanced_amount1, string net_amount1, string _status1, string station_id1)
    {

        StatusView statusCheck = new StatusView();
         Uri uri = new Uri(Constants.Bills_URL);
        var postData = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>("transaction_date",transaction_date1),//"2018-10-05 12:16:11"
                new KeyValuePair<string, string>("billing_date",billing_date1 ),//"2018-10-05"
                new KeyValuePair<string, string>("vehicle_id",vehicle_id1),//"1"
                new KeyValuePair<string, string>("customer_id", customer_id1),//"1"
                new KeyValuePair<string, string>("fuel_id",fuel_id1),//"1"
                new KeyValuePair<string, string>("fuel_unit_id",fuel_unit_id1 ),//"1"
                new KeyValuePair<string, string>("fuel_price_id",fuel_price_id1 ),//""
                new KeyValuePair<string, string>("price_per_unit",price_per_unit1 ),//"70"
                new KeyValuePair<string, string>("quantity", quantity1),//"10"
                new KeyValuePair<string, string>("amount",amount1 ),//"700"
                new KeyValuePair<string, string>("received_amount",recieved_amount1 ),//"0"
                new KeyValuePair<string, string>("advance_amount", advanced_amount1 ),//"0"
                new KeyValuePair<string, string>("net_amount",net_amount1 ),//"700"
                new KeyValuePair<string, string>("status",_status1 ),//"success"
                new KeyValuePair<string, string>("station_id",station_id1 )//"1"

            };

        HttpRequestMessage req = new HttpRequestMessage(HttpMethod.Post, uri);
        req.Content = new FormUrlEncodedContent(postData);

        using (HttpClient client = new HttpClient())
        {
            var response = await client.SendAsync(req);

            var content = await response.Content.ReadAsStringAsync();

            statusCheck = JsonConvert.DeserializeObject<StatusView>(content);
        }

        return statusCheck;

    }
}

Answers

Sign In or Register to comment.