Indy HTTP:读取 403 响应内容

发布于 2024-07-14 15:06:44 字数 504 浏览 5 评论 0原文

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

请参阅以下页面上的“ClientLogin 响应”部分:

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

当身份验证不正确或发生错误时,服务器会返回 403...正如预期的那样。 但是根据这个文档,响应内容中有客户端需要的信息,例如错误原因、验证码URL等。

问题是Indy IdHTTP组件抛出403异常,响应内容是空的。 到目前为止我还没有找到获取此内容的方法。 我尝试将对 Post 的调用包装在 try... except 中,然后读取响应流,但在 403 上它总是为空。

我将如何去做呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最美不过初阳 2024-07-21 15:06:44

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

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 也类似。)

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.)

还给你自由 2024-07-21 15:06:44

你是对的。 看起来在 TIdHTTPProtocol.ProcessResponse 中响应被读取,但之后被丢弃。 (甚至不设置为 nil)

但是应该很容易调整 CheckException 函数以将响应写入 IdHTTP.Response.ContentStream

也许您可以提交错误报告或功能请求。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文