Indy HTTP: reading response content at 403

I'm having a problem using Indy HTTP (in Delphi) with the Google Contacts API.

Refer to the "ClientLogin Response" section on the following page:

http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html

The server returns 403 when authentication is incorrect or an error occurs ... as expected. However, in accordance with this document there is information in the content of the response that the client requires, for example. cause of error and conversion URL, etc.

The problem is that the Indy IdHTTP component throws an exception at 403 and the response content is empty. So far, I have not found a way to this content. I tried wrapping the Post call in an attempt ... besides reading the response stream, but it is always empty at 403.

How can I do it?

+5
source share
2 answers

I have found a solution. It appears that the content is stored in the ErrorMessage field EIdHTTPProtocolException.

try 
   http.Post('https://www.google.com/accounts/ClientLogin', slReq);
except
   on E: EIdHTTPProtocolException do
      Memo1.Lines.Add(E.ErrorMessage);
end;

seems to be doing the trick.

(By the way, I'm using Indy 9. I'm sure Indy 10 is similar.)

+7
source

You're right. It seems that the TIdHTTPProtocol.ProcessResponseanswer is read, but then discarded. (And not even set to zero)

But you need to easily adapt the function CheckExceptionto record the response inIdHTTP.Response.ContentStream

You may be able to submit a bug report or feature request.

+2
source

All Articles