gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:53:39 34 4
gpt4 key购买 nike

我使用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/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com