Click here to Skip to main content
16,020,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi Friends,

I am sending values from windows application to net core web api.

I am not receiving values in the API.

Getting json deserialize error

Is there any alternative to send values to post api from windows applications?

What I have tried:

Windows application code :
WebClient client = new WebClient();

               client.BaseAddress = "http://test.com";
               var url = "/api/Customers/add";
               client.Headers["Content-type"] = "application/json";
               string StoreName = ConfigurationManager.AppSettings["StoreName"];
               List<Customersinfo> bills = new List<Customersinfo>();

               foreach (DataRow dr in dt.Rows)
               {

               Customersinfo Bill = new Customersinfo();
               Bill.Storename = StoreName;

               bills.Add(Bill);
              }

               string data = JsonConvert.SerializeObject(bills);
               var response = client.UploadString(url, data);

               var result = JsonConvert.DeserializeObject<Customersinfo>(response);


.net API:
[HttpPost]
        [Route("add")]
        public async Task<ObjectResult> AddCustomer([FromBody] List<Customersinfo> custinfo)
        {
            try
            {
                if (custinfo.Count > 0)
                {
					//Here I am not getting the data to insert into the database
				}
				
				}
				}
Posted
Comments
[no name] 10-Sep-22 7:05am    
Before you do anything else you should investigate why the error occurs. It may be something simple.
prasanna204 10-Sep-22 7:13am    
I worked on error and I wrote the same code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900