delphi - 如何跟踪 TIdHttp 的原始请求和响应内容

标签 delphi debugging indy idhttp

我使用delphi和python实现了相同的代码(发布表单)。 python 代码工作正常,但 delphi 代码失败。在 python 中,我可以简单地编写 httplib2.debuglevel=4 来查看实际发送到服务器的内容。但我不知道如何在delphi中打印内容。

def python_request_data(url, cookie, data):
    httplib2.debuglevel = 4
    conn = httplib2.Http()
    conn.follow_all_redirects = True
    headers = {'Cookie': cookie, 'Content-Type': 'application/x-www-form-urlencoded'}
    response, contents = conn.request(url, 'POST', data, headers=headers)

procedure DelphiRequestData(const Url, Cookie, Data: string);
var
  Client: TIdHttp;
  Params: TStringList;
  Response: string;
begin
  Client := TIdHttp.Create(nil);
  try
    Client.HTTPOptions := [hoKeepOrigProtocol];
    Client.Request.CustomHeaders.AddValue('Cookie', Cookie);
    Params := TStringList.Create;
    try
      Params.QuoteChar := #0;
      Params.Delimiter := '&';
      Params.DelimiterText := Data;
      Client.Request.ContentType := 'application/x-www-form-urlencoded';
      Client.Request.ContentLength := Length(Params.DelimitedText);
      Response := Client.Post(Url, Params);
    finally
      Params.Free;
    end;
  finally
    Client.Free;
  end;
end;

任何提示表示赞赏。

最佳答案

您可以使用 TIdLogDebug 作为 IdHttp 的拦截。
OnSend 和 OnReceive 事件将以数组或 TByte 的形式传递所需的信息。

关于delphi - 如何跟踪 TIdHttp 的原始请求和响应内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14011741/

相关文章:

multithreading - 如何在线程内接收 WM_POWERBROADCAST?

delphi - 如何从键=值对字符串中获取电子邮件地址?

c# - 当观察变量改变时暂停执行?

Delphi - 使用 Listview 管理 Indy TCPServer 连接

delphi - Indy 升级后的编码问题

delphi - 类名后面的尖括号在变量声明中意味着什么?

php - 如何在 Aptana IDE 中显示未定义的 php 变量通知?

c++ - 这个C++方法可以简化吗?

asp.net - 使用 Delphi 和 TIdHttp 将数据发布到 ASP .NET 页面

delphi - 如何绘制图像的一部分?