Are there headers you can send with a HTTP request that tell the web server to send you only headers in response and no body content?
I am using cURL to make such requests, but technically I assume it should be possible with simple header being sent as part of the request.
For example, there exists a 304 Not Modified HTTP Response Code. When you make a request to the server with your cache tag or datetime information, then the server can detect that and only return headers as a response that tell the user agent to use their cache as the response. This means that the response from the server is very, very small when it comes to bandwidth.
But is there a header you can send to servers that make the server only return a header and no body content?
The idea here is to make HTTP requests that otherwise might return large amount of data, very small. Such as an API call that would return JSON data or a log, when in fact the only thing user agent is interested in is making sure that the request went through and nothing else. This is in order to minimize the bandwidth to and from the server in cases where the body might exist, but is not necessary in any way in context to what the user agent is doing.
While it would be possible to design an API that listens to a specific custom header or whatnot, I'd rather not go this way unless I have to. But I've been unable to find if there is a standardized way to make a HTTP request that tells server not to send any body content?
You're looking for the verb
HEAD
. If you're using CURL with PHP, this will do the trick:If you are using PHP though (and it may very well also count in different situations), the script will continue to run until any output is sent (the note under
REQUEST_METHOD
). So if you're worried about the server stress, you might require something else if that fits.To me it looks like you're more looking for a 'ping', so why not simply request a file that does nothing but return an OK of some kind, perhaps even just the HTTP 200 OK (i.e. an empty file)?
If the server supports it, there is the
HEAD
action (as opposed to GET or POST). That tells the server to only send the headers, and no body.