0

I am writing a simple Web API application. I am writing a post method to add records like this:

[Route("api/{Inspection}/{post}/{date}/{inspectorId}/{unitID}/{time}")]
[HttpPost]
public void PostInspection(string date,int inspectorId,int unitID,string time)
{
    InspectionDataClass inspectionData = new InspectionDataClass();
    inspectionData.InsertRow(date,inspectorId,unitID,false,false,"", time);
}

and call the method in browser like this:

http://localhost:34367/api/inspection/97/3/13/10

but it doesn't execute.

1 Answer 1

1

Your attribute :

[Route("api/{Inspection}/{post}/{date}/{inspectorId}/{unitID}/{time}")]

But you browser url with:

http://localhost:34367/api/inspection/97/3/13/10

Did you have miss the path for /{post}/?

And sorry for my last wrong anser and my pool English.I thought you have using asp.net core.

Sign up to request clarification or add additional context in comments.

6 Comments

thank you for your response but I get new error:" HttpPostAttribute' does not contain a constructor that takes 1 arguments" I use visual studio 2015 ...
I'm sorry for i make a mistake,your attribute with Rout is [Route("api/{Inspection}/{post}/{date}/{inspectorId}/{unitID}/{time}")] and the path whith {post} do not contain in your browser url:localhost:34367/api/inspection/97/3/13/10
Thank you very much for your help, and your guide. I change url to " localhost:34367/api/inspection/post/97/3/13/10" but I see this message in browser : " "Message": "The requested resource does not support http method 'GET'." " Do you know this Reason?
Becuse you use browser,They use HttpGet.You can download Postman getpostman.com and use post method to test your api
my problem is solving with your help ..Thank you very much
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.