Suman Raj

Suman Raj

  • NA
  • 287
  • 13.4k

Can't able to send json data to C# api in winform

Mar 13 2021 4:56 AM
Am unable to post json data to api using c# winform with parameter jsondata, the following steps i used to send data every time i tried same issue raising the code & errors are attached to this post.
 
URL & Datas as follows:
url: https:\\xxx.com\:jsondata
 
Step 1:
 
jsondata=
[{
"Name": "Raj",
"Mobile": "5546546556"
},
{
"Name": "Raj",
"Mobile": "5546546546"
}
]
 
Step 2:
 
jsondata=
{
"Name": "Raj",
"Mobile": "5546546526"
}
 
ERROR:
{"status":"FAILURE","Error":"A JSONObject text must begin with '{' at character 1 of &"}
Error Image:
 
Code in C#:
  1. public static async Task CallInvoiceAPI(string jsondata, string url)  
  2. {  
  3. try  
  4. {  
  5. HttpClient client = new HttpClient();  
  6. var response = client.PostAsJsonAsync(url, jsondata).Result;  
  7. var content = response.Content;  
  8. var result = await content.ReadAsStringAsync();  
  9. if (result.Contains("SUCCESS"))  
  10. strStatus = "Success";  
  11. else  
  12. strStatus = "Failed";  
  13. }  
  14. catch (Exception ex)  
  15. {  
  16. strStatus = "Failed";  
  17. }  
  18. }  

Answers (4)