Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
709 views
in Technique[技术] by (71.8m points)

curl - Sending a HTTP request that tells server to return only headers and no body?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...