读取403上的响应内容

读取403上的响应内容

本文介绍了Indy HTTP:读取403上的响应内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用带有Google Contacts API的Indy HTTP(在Delphi中)时遇到问题。

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

请参阅下页的ClientLogin Response部分:

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

当身份验证不正确或发生错误时,服务器返回403。正如所料。然而,根据该文档,客户端需要的响应内容中存在信息,例如,错误原因和验证码URL等。

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.

问题是Indy IdHTTP组件在403上抛出异常而响应内容为空。到目前为止,我还没有找到这个内容。我尝试将试一试包裹在Post中...除了然后读取响应流,但它总是在403上空。

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.

我将如何进行这样做?

推荐答案

我找到了解决方案。看起来内容存储在EIdHTTPProtocolException的ErrorMessage字段中。

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;

似乎可以解决问题。

(顺便说一句,我使用的是Indy 9.我相信Indy 10很相似。)

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

这篇关于Indy HTTP:读取403上的响应内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:39