来自服务器idhttp的XML响应

时间:2012-10-18 08:18:44

标签: xml delphi networking idhttp

获取发送请求到服务器并收到错误409,程序被暂停,使用try除了并忽略她,我还有错误409和XML响应,我该如何阅读?

HTTP.Response.gettext - 不给我,只提供有关服务器的信息

http.response.rawheaders.commatext - 仅有关服务器的信息

内容长度匹配

答案可以在嗅探器中看到

我在程序中得到答案?

1 个答案:

答案 0 :(得分:1)

TIdHTTP收到来自服务器的HTTP错误(如409)时,它会引发EIdHTTPProtocolException异常,并且错误的内容文本将位于其ErrorMessage属性中,例如:

try
  IdHTTP1.Get(...);
except
  on E: EIdHTTPProtocolException do
  begin
    // HTTP-specific error
    ShowMessage(Format('HTTP Error'#13'Response: %d %s'#13'Content: %s', [E.ErrorCode, E.Message, E.ErrorMessage]));
  end;
  on E: Exception do
  begin
    // any other error
    ShowMessage(Format('Exception'#13'Class: %s'#13'%s', [E.ClassName, E.Message]));
  end;
end;

当您遇到密码错误时,它应显示一个弹出消息框,说明以下内容:

HTTP Error
Response: 409 Conflict
Content: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><error code="10003" appid="1"><failure cause="INVALID_PASSWORD" field="password" value="******"/></error>