views:

62

answers:

4

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.

+2  A: 

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.

SLaks
Why was this downvoted?
SLaks
A: 

You could send a HEAD request, if the server you are calling support it - the response will typically be way smaller than a GET.

Ray
+4  A: 

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

OPTIONS Returns the HTTP methods that the server supports for specified URL. This can be used to check the functionality of a web server by requesting '*' instead of a specific resource.

More information here

Chris McCauley
Caveat: If the URL ends up running a script that doesn't know how to handle OPTIONS (e.g., most PHP scripts :-P), the results may be unpredictable. :-)
Chris Jester-Young
Updated with a warning but a bad application could do anything with any request.
Chris McCauley
A: 

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.

Laykes