Invalid input data in postman!! Postman test API asp.net core

Invalid input data in postman!! Postman test API asp.net core

I want to test API in postman, but I receive invalid input. It’s code httPost in asp.net core

Invalid input data in postman!! Postman test API asp.net core

It’s in PostMan. Please help me!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

public IActionResult GetTopInfor([FromBody] JObject p)

In your action method, we can find that it accepts a JObject type parameter.

Firstly, please note that JObject is a class that belongs to Newtonsoft.Json, since .NET Core 3, the default JSON serializer for ASP.NET Core is now System.Text.Json.

To make it can handle JObject parameter well, please check if you add Newtonsoft.Json (Json.NET) support by calling AddNewtonsoftJson, for more information, please check following doc:

https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#use-newtonsoftjson-in-an-aspnet-core-30-mvc-project

Besides, please debug your code to trace the actual value of p and check if any exception is thrown while you invoke your custom service _orderService.GetTopInfor(row).

Test Result

Invalid input data in postman!! Postman test API asp.net core

Method 2

You can use ex.Message.ToString() instead of GetErrorMsg(6).

Method 3

When dealing with JObject, you get the value using GetValue() method.
try this :

row = Int32.Parse(p.GetValue("row").ToString());

also, your code is a bit all over the place. you should rearrange it to make it more readable.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x