开发者

How to know if function is accessed from a form or api call

I'm using an MVC framework. I have a URL like example.com/submit which displays a form that submits to itself, but I also want it to support programmatic submission (like an API). How can I find out if the url is being called by someone who typed the url and filled out the form and submi开发者_如何学Ctted it, or by someone who is doing it programatically with the api? Is there something in the headers or any other way to get a clue?


You can include a hidden field in your form that tells your application that it was sent through the HTML form. This field should only be used by your form and not by API calls. In that way you can easily differentiate between the calls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜