Indy的TIdHttp类在最近的版本中有一个Delete()例程.但由于某种原因,这是一个程序,而不是一个功能. Put(),Get()等都是返回响应主体内容的函数.作为字符串或将其传递给TStream.使用Delete()是不可能的,这与DELETE的定义相矛盾:
A successful response SHOULD be 200 (OK) if the response includes an entity describing the status,202 (Accepted) if the action has not yet been enacted,or 204 (No Content) if the action has been enacted but the response does not include an entity.
然后我尝试使用GetResponse(),但它只是简单地关闭了我的连接,而没有填写响应.
那么如何从DELETE响应中读取响应主体的内容?
解决方法@H_502_14@
您需要更新Indy安装. 2013年9月在SVN修订版5056中为此功能请求添加了用于获取DELETE方法响应的超载:
Add overloads for TIdHTTP Delete() and Options() methods that can output a response’s message body
如果由于某种原因不想更新Indy,可以继承TIdHTTP组件并添加一个将响应流传递给DoRequest方法的方法,例如:
type
TIdHTTP = class(IdHTTP.TIdHTTP)
public
procedure DeleteEx(AURL: string; AResponseContent: TStream);
end;
implementation
{ TIdHTTP }
procedure TIdHTTP.DeleteEx(AURL: string; AResponseContent: TStream);
begin
DoRequest(Id_HTTPMethodDelete,AURL,nil,AResponseContent,[]);
end;
Add overloads for TIdHTTP Delete() and Options() methods that can output a response’s message body
如果由于某种原因不想更新Indy,可以继承TIdHTTP组件并添加一个将响应流传递给DoRequest方法的方法,例如:
type TIdHTTP = class(IdHTTP.TIdHTTP) public procedure DeleteEx(AURL: string; AResponseContent: TStream); end; implementation { TIdHTTP } procedure TIdHTTP.DeleteEx(AURL: string; AResponseContent: TStream); begin DoRequest(Id_HTTPMethodDelete,AURL,nil,AResponseContent,[]); end;