Indy HTTP:读取 403 响应内容
我在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案。 看起来内容存储在 EIdHTTPProtocolException 的 ErrorMessage 字段中。
似乎可以解决问题。
(顺便说一下,我使用的是 Indy 9。我确信 Indy 10 也类似。)
I've found a solution. Looks like the content is stored in the ErrorMessage field of EIdHTTPProtocolException.
seems to do the trick.
(By the way, I am using Indy 9. I am sure Indy 10 is similar.)
你是对的。 看起来在 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 intoIdHTTP.Response.ContentStream
Perhaps you could file a bug report or a feature request.