★★500分帮忙调式IdHTTPpost程序(源码) ( 积分: 200 )

  • 主题发起人 主题发起人 abencat
  • 开始时间 开始时间
A

abencat

Unregistered / Unconfirmed
GUEST, unregistred user!
//运行通过没有错误 可是就是不能发表留言内容
//???????????????
procedure TForm1.Button3Click(Sender: TObject);
function makediy():string;
var
IdHTTP: TIDHttp;
myParams:tStringList;
ret:TStringStream;
S,Cookie:string;
i: integer;
begin
IdHTTP := TIDHttp.Create(nil);
IdHTTP.ReadTimeout := 30*1000;
ret:=tstringstream.Create('');
myParams:=tStringList.Create;

S := IdHttp.Get('http://localhost/webb/book.asp?action=Add_New');
Memo1.Text := S;

// 从返回的页面中找出cookie, 并增加到http.Request中
for i := 0 to IdHttp1.Response.RawHeaders.Count -1 do
if UpperCase(LeftStr(IdHttp1.Response.RawHeaders, 10)) = 'SET-COOKIE' then
begin
Cookie := Trim(Copy(IdHttp1.Response.RawHeaders, 12, MaxInt));
Cookie := Copy(Cookie, 1, Pos(';', Cookie) - 1);
IdHttp.Request.RawHeaders.Add('Cookie:'+ Cookie);
end;

myParams.Add('name=标题容');
myParams.Add('SEX=0');
myParams.Add('email=');
myParams.Add('qq=11112');
myParams.Add('web=www.163.com');
myParams.Add('city=11111');
myParams.Add('title=1');
myParams.Add('words=内容士大夫士大夫');
myParams.Add('admin=0');
myParams.Add('comeurl=http://localhost/webb/book.asp?action=Add_New');
myParams.Add('Submit=提交');

try
IdHTTP.HTTPOptions:=[];
IdHttp.Post('http://localhost/webb/book.asp?Add_New_Execute',myParams,ret);
//IdHTTP.Post('http://localhost/asp/ac.asp',myParams,ret);
Ret.Position:=0;
form1.Memo1.Lines.LoadFromStream(ret);
finally
IdHTTP.Disconnect;
FreeAndNil(IdHTTP);
FreeAndNil(myParams);
end;
end;
begin
makediy();
end;
 
//运行通过没有错误 可是就是不能发表留言内容
//???????????????
procedure TForm1.Button3Click(Sender: TObject);
function makediy():string;
var
IdHTTP: TIDHttp;
myParams:tStringList;
ret:TStringStream;
S,Cookie:string;
i: integer;
begin
IdHTTP := TIDHttp.Create(nil);
IdHTTP.ReadTimeout := 30*1000;
ret:=tstringstream.Create('');
myParams:=tStringList.Create;

S := IdHttp.Get('http://localhost/webb/book.asp?action=Add_New');
Memo1.Text := S;

// 从返回的页面中找出cookie, 并增加到http.Request中
for i := 0 to IdHttp1.Response.RawHeaders.Count -1 do
if UpperCase(LeftStr(IdHttp1.Response.RawHeaders, 10)) = 'SET-COOKIE' then
begin
Cookie := Trim(Copy(IdHttp1.Response.RawHeaders, 12, MaxInt));
Cookie := Copy(Cookie, 1, Pos(';', Cookie) - 1);
IdHttp.Request.RawHeaders.Add('Cookie:'+ Cookie);
end;

myParams.Add('name=标题容');
myParams.Add('SEX=0');
myParams.Add('email=');
myParams.Add('qq=11112');
myParams.Add('web=www.163.com');
myParams.Add('city=11111');
myParams.Add('title=1');
myParams.Add('words=内容士大夫士大夫');
myParams.Add('admin=0');
myParams.Add('comeurl=http://localhost/webb/book.asp?action=Add_New');
myParams.Add('Submit=提交');

try
IdHTTP.HTTPOptions:=[];
IdHttp.Post('http://localhost/webb/book.asp?Add_New_Execute',myParams,ret);
//IdHTTP.Post('http://localhost/asp/ac.asp',myParams,ret);
Ret.Position:=0;
form1.Memo1.Lines.LoadFromStream(ret);
finally
IdHTTP.Disconnect;
FreeAndNil(IdHTTP);
FreeAndNil(myParams);
end;
end;
begin
makediy();
end;
 
顶~~~~~~~~~~~~~~~~~~~~
 
我可以帮助你测试一下
 
谢谢,先顶起来再说吧
 
编译不过去阿
HTML:=IdHttp1.Post(BaseURL,Params);
这行参数不够啊。
你是什么版本的delphi
 
我没装D7,呵呵,帮不了你了。
不过有个Params没释放
 
提示“http/1.1 302 object moved”
 
//运行通过没有错误 可是就是不能发表留言内容
//???????????????
procedure TForm1.Button3Click(Sender: TObject);
function makediy():string;
var
IdHTTP: TIDHttp;
myParams:tStringList;
ret:TStringStream;
S,Cookie:string;
i: integer;
begin
IdHTTP := TIDHttp.Create(nil);
IdHTTP.ReadTimeout := 30*1000;
ret:=tstringstream.Create('');
myParams:=tStringList.Create;

S := IdHttp.Get('http://localhost/webb/book.asp?action=Add_New');
Memo1.Text := S;

// 从返回的页面中找出cookie, 并增加到http.Request中
for i := 0 to IdHttp1.Response.RawHeaders.Count -1 do
if UpperCase(LeftStr(IdHttp1.Response.RawHeaders, 10)) = 'SET-COOKIE' then
begin
Cookie := Trim(Copy(IdHttp1.Response.RawHeaders, 12, MaxInt));
Cookie := Copy(Cookie, 1, Pos(';', Cookie) - 1);
IdHttp.Request.RawHeaders.Add('Cookie:'+ Cookie);
end;

myParams.Add('name=标题容');
myParams.Add('SEX=0');
myParams.Add('email=');
myParams.Add('qq=11112');
myParams.Add('web=www.163.com');
myParams.Add('city=11111');
myParams.Add('title=1');
myParams.Add('words=内容士大夫士大夫');
myParams.Add('admin=0');
myParams.Add('comeurl=http://localhost/webb/book.asp?action=Add_New');
myParams.Add('Submit=提交');

try
IdHTTP.HTTPOptions:=[];
IdHttp.Post('http://localhost/webb/book.asp?Add_New_Execute',myParams,ret);
//IdHTTP.Post('http://localhost/asp/ac.asp',myParams,ret);
Ret.Position:=0;
form1.Memo1.Lines.LoadFromStream(ret);
finally
IdHTTP.Disconnect;
FreeAndNil(IdHTTP);
FreeAndNil(myParams);
end;
end;
begin
makediy();
end;
 
简单的是通过了,请问我望留言板上怎么不能发送上去呢
 
procedure TForm1.Button3Click(Sender: TObject);
function makediy():string;
var
IdHTTP: TIDHttp;
myParams:tStringList;
ret:TStringStream;
S,Cookie:string;
i: integer;
begin
IdHTTP := TIDHttp.Create(nil);
IdHTTP.ReadTimeout := 30*1000;
ret:=tstringstream.Create('');
myParams:=tStringList.Create;

S := IdHttp.Get('http://localhost/webb/book.asp?action=Add_New');
Memo1.Text := S;

// 从返回的页面中找出cookie, 并增加到http.Request中
for i := 0 to IdHttp1.Response.RawHeaders.Count -1 do
if UpperCase(LeftStr(IdHttp1.Response.RawHeaders, 10)) = 'SET-COOKIE' then
begin
Cookie := Trim(Copy(IdHttp1.Response.RawHeaders, 12, MaxInt));
Cookie := Copy(Cookie, 1, Pos(';', Cookie) - 1);
IdHttp.Request.RawHeaders.Add('Cookie:'+ Cookie);
end;

[red] //从这里开始,下面的代码通通改成
myParams.Add('name=' + TIdURI.ParamEncode('标题容'));
//下面全部改,依此类推,这是给Param编码,还有,记得在uses部分引用IdURI(最后一个字符是英文i的大写,不是L)
[/red]
myParams.Add('SEX=0');
myParams.Add('email=');
myParams.Add('qq=11112');
myParams.Add('web=www.163.com');
myParams.Add('city=11111');
myParams.Add('title=1');
myParams.Add('words=内容士大夫士大夫');
myParams.Add('admin=0');
myParams.Add('comeurl=http://localhost/webb/book.asp?action=Add_New');
myParams.Add('Submit=提交');

try
IdHTTP.HTTPOptions:=[];
IdHttp.Post('http://localhost/webb/book.asp?Add_New_Execute',myParams,ret);
//IdHTTP.Post('http://localhost/asp/ac.asp',myParams,ret);
Ret.Position:=0;
form1.Memo1.Lines.LoadFromStream(ret);
finally
IdHTTP.Disconnect;
FreeAndNil(IdHTTP);
FreeAndNil(myParams);
end;
end;
 
请把里面的地址 'http://localhost/webb/book.asp 修改为 'http://www.abmsoft.cn/book.asp进行测试
 
自己继续顶~~~~~~~~~~~~~~~~~~
 
继续求答案,请高手帮忙了
 
测试OK,提交的与需求的内容不太一致!

以下为稍修正后的代码.

function makediy():string;
var
IdHTTP: TIDHttp;
myParams:tStringList;
begin

myParams:=tStringList.Create;
IdHTTP := TIDHttp.Create(nil);

IdHTTP.ReadTimeout := 30*1000;

// Memo1.Text := IdHttp.Get('http://www.abmsoft.cn/book.asp?action=Add_New');

myParams.Add('name=DFW');
myParams.Add('SEX=0');
myParams.Add('email=xxx@xxx.cc');
myParams.Add('qq=11112');
myParams.Add('web=163.com');
myParams.Add('city=11111');
myParams.Add('title=1');
myParams.Add('words=ϵͳ²âÊÔÇë¹ÜÀíԱɾ³ý!');
myParams.Add('admin=0');
myParams.Add('Submit=Ìá½»');
myParams.Add('action_e=Add_New');

try
Result := IdHttp.Post('http://www.abmsoft.cn/book.asp?Add_New_Execute', myParams);//, ret);
finally
FreeAndNil(IdHTTP);
FreeAndNil(myParams);
end;
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
memo1.Text := makediy();
end;
 
还有点不清楚,请问myParams.Add('action_e=Add_New'); 这个参数你是怎么得到的,还请说明
 
仔细看一下生成的HTML就可以了.

你的BBS的测试已经OK,要范例请来EMAIL. 你的DELPHIBBS上留的EMAIL发不到.
 
好的 QQ:15524227
abmsoft@163.com abmsoft@21cn.com
 
MSN:abencatgao@hotmail.com
 
后退
顶部