加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 09:52:15 所属栏目:大数据 来源:网络整理
导读:我使用delphi和 python实现了相同的代码(发布表单). python代码运行完美,但delphi代码失败.在python中,我可以简单地编写httplib2.debuglevel = 4来查看实际发送到服务器的内容.但我不知道如何在delphi中打印内容. def python_request_data(url,cookie,data):
我使用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将在数组或TBytes中提供所需的信息.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读