【发布时间】:2015-06-01 01:01:53
【问题描述】:
我花了几个小时试图理解为什么这根本行不通,但没有成功;(
我想用我的 delphi 应用程序发送私人消息。
我可以登录、阅读和删除消息,但我无法发送消息(我的论坛使用 phpbb3)。
分析帖子数据,我得到了这个:
Post URL: http://example.com/ucp.php?i=pm&mode=compose&action=post&sid=xxxxx
Post Data:
username_list=
icon=0
subject=assunto
message=texto
address_list[u][2]=to
lastclick=xxxx
status_switch=0
post=Submit
attach_sig=on
creation_time=xxxx
form_token=xxx
发送前我需要获取的 xxx 值。我已经手动检查了这些值,它们是正确的。
我的代码:
procedure Envia();
var
form_token, cr_time, sid: string;
pp: TStringList;
begin
//download the page to get the values (token, sid...)
FPageSource.Text := FCon.Get('http://example.com/ucp.php?i=pm&mode=compose&u=2');
//form token
form_token := TRegEx.Match(FPageSource.Text, 'form_token" value="(\w+)"').Groups[1].Value;
//creation time
cr_time := TRegEx.Match(FPageSource.Text, 'creation_time" value="(\w+)"').Groups[1].Value;
//sid
sid := TRegEx.Match(FPageSource.Text, 'sid=(\w+)').Groups[1].Value;
//data
pp := TStringList.Create;
pp.Add('username_list=');
pp.Add('icon=0');
pp.Add('subject=assunto');
pp.Add('message=mensagem');
pp.Add(HttpEncode('address_list[u][2]') + '=to');
pp.Add('lastclick=' + cr_time);
pp.Add('status_switch=0');
pp.Add('post=Submit');
pp.Add('attach_sid=on');
pp.Add('creation_time=' + cr_time);
pp.Add('form_token=' + form_token);
//send
FPageSource.Text := FCon.Post('http://example.com/ucp.php?i=pm&mode=compose&action=post&sid=' + sid, pp);
//The result in FPageSource is my inbox, my post data was
//ignored by phpbb ;(
end;
注意:
- FCon = TIdHttp
- FPageSource = TStringList
- HttpEncode = HttpApp 单元中的函数
- 使用 Delphi xe6
-- 我已经使用 Opera 发送了一条消息,并使用 Fiddler here the image 捕获了帖子数据。可以看到,数据结构都是一样的,为什么不行呢?
【问题讨论】:
-
你捕获了来自 Opera 的请求;您的程序中的等效捕获在哪里?他们匹配吗?换句话说,你怎么知道你真的发送了你认为发送的内容?
-
@RobKennedy 发布的数据是一样的,但是返回码是302,如果你仔细看你会发现body size是0。查看新图片:New Image--编辑:HandleRedirects = true,结果相同 >.
-
标题呢?既发送又接收。它们也一样吗?
-
@RobKennedy Another Image 你认为 keep-alive 是造成这种情况的原因吗?
-
我对此表示怀疑,尽管其位置的 Expect 标头看起来很可疑。我想你越来越近了。从 IP 地址,我假设您可以访问服务器。也许你可以检查它的日志,看看服务器认为发生了什么。
标签: delphi