Search code examples
delphihttpindy

Get server data in Delphi 2010


I have a problem I'm trying to use the component idhttp using indy in delphi 2010, the problem is I'm trying to get the following information when using idHTTP1.Head ():

HTTP/1.1 200 OK
Date: Mon, 16 Jun 2003 2:53:29 GMT
Server: Apache/1.3.3 (Unix) (Red Hat / Linux)
Last-Modified: Wed, October 7, 1998 11:18:14 GMT
ETag: "1813-49b-361b4df6"
Accept-Ranges: bytes
Content-Length: 1179
Connection: close
Content-Type: text / html

The problem is not that I have to do to get this information because I can not get with idHTTP1.Request.RawHeaders.Values​​, someone could say that I have to do.


Solution

  • You are looking in the wrong place. You need to look in IdHTTP1.**Response**.RawHeaders instead. Also, all of those values actually have individual properties associated with them, eg:

    IdHTTP1.Response.ResponseVersion
    IdHTTP1.Response.ResponseCode
    IdHTTP1.Response.ResponseText
    IdHTTP1.Response.Date
    IdHTTP1.Response.Server
    IdHTTP1.Response.LastModified
    IdHTTP1.Response.ETag
    IdHTTP1.Response.AcceptRanges
    IdHTTP1.Response.ContentLength (also IdHTTP1.Response.HasContentLength)
    IdHTTP1.Response.Connection
    IdHTTP1.Response.ContentType