Kim HJ
Kim HJ

Reputation: 1192

How to read the header from a TIdHTTP get

I'm using TIdHTTP.Get() to retrieve records in a JSON format. It will only send me the first 1000 records, and in the header it will have the URL for the next 1000, if there are any.

I can see the header in PostMan, but how do I access it from this call?

jsontxt := IdHTTP1.Get(url);

Upvotes: 1

Views: 3907

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 598434

Once TIdHTTP.Get() exits, the raw response headers can be accessed via the TIdHTTP.Response.RawHeaders property. Many headers also have their own dedicated sub-property in the TIdHTTP.Response object. If your desired header does not, you can use the RawHeaders.Values[] property to read it, eg:

jsontxt := IdHTTP1.Get(url);
url := IdHTTP1.Response.RawHeaders.Values['the-next-url-header'];

If the header does not exist, Values[] will simply return a blank string, eg:

url := ...;
repeat
  jsontxt := IdHTTP1.Get(url);
  //...
  url := IdHTTP1.Response.RawHeaders.Values['the-next-url-header'];
until url = '';

Upvotes: 4

Related Questions