Hazz22
Hazz22

Reputation: 1010

C# get the HTTP Headers of a GET request without body

I've got a bit of an odd problem. I'm trying to get the headers of a webpage WITHOUT the body being sent through. This request will happen often, so what I'm doing is checking the Last-Modified, Etag, and Content-Length headers for changes. But as the page I'm checking is large, I don't want to download the body.

I know that there is a specific HEAD request which can be used in C#, but when using this the server sends back different headers than the standard GET request. The HEAD request doesn't contain any of the headers that I'm looking for.

Anyone out there got any ideas?

Upvotes: 2

Views: 1566

Answers (3)

Naveen
Naveen

Reputation: 683

If you set the Range header value to bytes=0-0 and perform the request, you will get header with a 1 byte body. This only works if the server supports serving ranges.

Upvotes: 1

Naren
Naren

Reputation: 2311

Without using the HEAD request it is not possible .Better refer this link.

Upvotes: 1

Vladimir Gondarev
Vladimir Gondarev

Reputation: 1243

There is no way(except HEAD request) to get headers without the body. Server sends all data anyway.

I strongly suggest you to reconsider the app/system architecture, if it's not too late. If I had the web server that you request I would block all connection from you. If server belongs to you then consider to implement a notification or something similar.

Upvotes: 0

Related Questions