有没有办法检查 POST url 是否存在?
有没有办法在不实际发送 POST 请求的情况下确定 POST 端点是否存在?
对于 GET 端点,检查 404 不是问题,但我想检查 POST 端点而不触发远程 URL 上的任何操作。
Is there any way to determine if a POST endpoint exists without actually sending a POST request?
For GET endpoints, it's not problem to check for 404s, but I'd like to check POST endpoints without triggering whatever action resides on the remote url.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
发送 OPTIONS 请求可能有效
它可能不会被广泛实现,但执行此操作的标准方法是通过 OPTIONS 动词。
警告: 这应该是幂等的,但不合规的服务器可能会做非常糟糕的事情
更多信息此处
Sending an OPTIONS request may work
It may not be implemented widely but the standard way to do this is via the OPTIONS verb.
WARNING: This should be idempotent but a non-compliant server may do very bad things
More information here
根据定义这是不可能的。
您要发布到的 URL 可以由任何东西运行,并且不要求服务器行为一致。
您能做的最好的事情就是发送 GET 并看看会发生什么;然而,这会导致误报和漏报。
This is not possible by definition.
The URL that you're posting to could be run by anything, and there is no requirement that the server behave consistently.
The best you could do is to send a GET and see what happens; however, this will result in both false positives and false negatives.
如果您调用的服务器支持 HEAD 请求,您可以发送 HEAD 请求 - 响应通常会比 GET 小得多。
You could send a HEAD request, if the server you are calling support it - the response will typically be way smaller than a GET.
端点=脚本吗?这有点令人困惑。
我首先要指出,如果它不存在,你为什么要在某个地方发布?好像有点傻?
无论如何,如果您的 POST URL 确实存在一些不确定因素,您可以使用 cURL,然后在 cURL 响应中设置标头选项。我建议您在执行此操作时保存所有经过验证的 POST(如果 POST url 可能会再次使用)。
您可以在执行 CURL 的同时发送整个 POST,然后检查是否出错。
我想你可能自己在你的问题标签中用 cURL 回答了这个问题。
Does endpoint = script? It was a little confusing.
I would first point out, why would you be POSTing somewhere if it doesn't exist? It seems a little silly?
Anyway, if there is really some element of uncertainty with your POST URL, you can use cURL, then set the header option in the cURL response. I would suggest that if you do this that you save all validated POSTs if its likely that the POST url would be used again.
You can send your entire POST at the same time as doing the CURL then check to see if its errored out.
I think you probably answered this question yourself in your tags of your question with cURL.