2012-10-18 176 views
-2

獲取發送請求到服務器並收到錯誤409,程序被暫停,使用try除了忽略她,我也有一個錯誤409和XML響應,我怎麼讀它?來自服務器的XML響應idhttp

HTTP.Response.gettext - 它不給我,只有服務器

http.response.rawheaders.commatext的信息 - 只有服務器的信息

內容lenght匹配

答案可以在嗅探器中看到

我在程序中得到答案?

+0

如何得到答案? – user1748535

+0

獲取什麼答案?響應內容?你如何獲取代碼中的內容?你甚至試過從我的(現在刪除)文章中的代碼? – TLama

+0

HTTP/1.1 409衝突 Content-Type:text/xml; charset = utf-8 服務器:Jetty(6.1.x) 內容長度:160 連接:保持活動 <?xml version =「1.0」encoding =「UTF-8」standalone =「yes」?> user1748535

回答

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> 
相關問題