Indy HTTP: reading response content on a 403

一曲冷凌霜 提交于 2019-12-10 14:12:25

问题


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

Please refer to the section "ClientLogin Response" on the following page:

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

The server returns a 403 when the authentication is incorrect or an error occurs... as expected. However, according to this document, there is information in the response content that is needed by the client, e.g. the error reason, and captcha URL, etc.

The problem is that the Indy IdHTTP component throws an exception on a 403 and the response content is empty. I have found no way so far to get to this content. I've tried wrapping the call to Post in a try...except then reading the response stream, but it always empty on a 403.

How would I go about doing this?


回答1:


I've found a solution. Looks like the content is stored in the ErrorMessage field of EIdHTTPProtocolException.

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

seems to do the trick.

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




回答2:


You are right. It seems in TIdHTTPProtocol.ProcessResponse the response is read but after that discarded. (And not even set to nil)

But it should be easy to adapt the CheckException function to write the response into IdHTTP.Response.ContentStream

Perhaps you could file a bug report or a feature request.



来源:https://stackoverflow.com/questions/607876/indy-http-reading-response-content-on-a-403

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!