idhttp在post表单的问题

cnotes 2012-04-09 04:39:58
1、要post的页面里的变量有的是必填项,有的是可选的;是不是只要post页面里必填的变量就可以了?
2、如何取得post后返回的数据?
3、有没有比idhttp好用的控件?
...全文
550 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
wzca 2012-04-15
  • 打赏
  • 举报
回复
cnotes 2012-04-15
  • 打赏
  • 举报
回复
会不会是cookie的问题?
wzca 2012-04-15
  • 打赏
  • 举报
回复
已经发送。请查收
cnotes 2012-04-15
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 的回复:]

就这一个unit,没别的了,我用的是XE2
Delphi(Pascal) code
unit Unit2;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, ……
[/Quote]

跟我写的差不多啊 ,你的代码也是没有成功的,没有弹出ok的提示。但是你的动画里的有。。奇怪,能不能把代码传到给我,我给你发信息了
cnotes 2012-04-15
  • 打赏
  • 举报
回复
[Quote=引用 21 楼 的回复:]

[/Quote]

还有动画呢,来晚了,我先看看!!
wzca 2012-04-13
  • 打赏
  • 举报
回复
就这一个unit,没别的了,我用的是XE2
unit Unit2;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP, Vcl.StdCtrls, IdCookieManager;

type
TForm2 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
HTTP: TIdHTTP;
IdCookieManager1: TIdCookieManager;
Button3: TButton;
Memo2: TMemo;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button2Click(Sender: TObject);
private
Html: string;
postURL: string;
cssList, inputList: TStrings;
function GetSubString(BeginStr, EndStr: string): string;
function SearchCss(InputField: string): Boolean;
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.dfm}

const
urlGet = 'http://www.eset.eu/download/ess-trial-form';

procedure TForm2.Button1Click(Sender: TObject);
var
sURL: string;
begin
Html := HTTP.Get(urlGet); // 取出主页
// 得到Post页
sURL := GetSubString('<iframe src="', '" width="100%"');
Http.Request.Referer := urlGet;
// 第二次Get, 取到被加密的 Form
sURL := 'Http://www.eset.eu' + sURL;
postURL := sURL;
Html := Http.Get(sURL);
Memo1.Text := Html;
end;

procedure TForm2.Button2Click(Sender: TObject);
var
Dest: TStringStream;
begin
Dest := TStringStream.Create('', TEncoding.GetEncoding(936));
Http.Post(postURL, inputList, Dest);
Dest.Seek(0, 0);
Memo2.Lines.LoadFromStream(Dest);
Dest.Free;
if Pos('<div>A new license has been sent to', Memo2.Text) > 0 then
ShowMessage('OK');
end;

procedure TForm2.Button3Click(Sender: TObject);
var
cssLine, inputField, fieldValue: string;
begin
cssList.Clear;
Html := Memo1.Text;
Html := GetSubString('<style type="text/css">', '</style>');
repeat
cssLine := GetSubString('#', '}');
if cssLine <> '' then
cssList.Add(cssLine);
until (cssLine = '');

inputList.Clear;
Html := Memo1.Text;
repeat
inputField := GetSubString('<input type="text" name="', '"');
if inputField <> '' then
begin
fieldValue := GetSubString('value="', '"');
if fieldValue = '' then
begin
if SearchCss(inputField) then
inputlist.Add(inputField + '=' + Edit1.Text)
else
inputList.Add(inputField + '=');
end
else
begin
inputList.Add(inputField + '=' + fieldValue);
end;
end;
until (inputField='');
// add Submit line
inputField := GetSubString('<input type="submit" name="', '"');
fieldValue := GetSubString('value="', '"');
inputList.Add(inputField + '=' + fieldValue);
// add Hide Line
inputField := GetSubString('<input type="hidden" name="', '"');
fieldValue := GetSubString('value="', '"');
inputList.Add(inputField + '=' + fieldValue);
Memo2.Lines.Assign(inputList);
ShowMessage('Down');
end;

procedure TForm2.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
cssList.Free;
inputList.Free;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
cssList := TStringList.Create;
inputList := TStringList.Create;
end;

function TForm2.GetSubString(BeginStr, EndStr: string): string;
var
nPos: Integer;
begin
nPos := Pos(BeginStr, Html);
if nPos = 0 then
begin
Result := '';
Exit;
end;
Html := Copy(Html, nPos + Length(BeginStr) , MaxInt);
nPos := Pos(EndStr, Html);
if nPos = 0 then
nPos := MaxInt;
Result := Copy(Html, 1, nPos -1);
Html := Copy(Html, nPos + Length(EndStr), MaxInt);
end;

function TForm2.SearchCss(InputField: string): Boolean;
var
i: Integer;
begin
Result := False;
for I := 0 to cssList.Count -1 do
begin
if Pos(InputField, cssList.Strings[i]) > 0 then
begin
if Pos('display: block;', cssList.Strings[i]) > 0 then
Result := True;
Break;
end;
end;
end;

end.
wzca 2012-04-13
  • 打赏
  • 举报
回复
已经弄好了,不过我那天连着三次回复,就不让我再贴了。。。随闷
cnotes 2012-04-13
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 的回复:]

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
害死人啊

用WebBrowers 应该是个好注意

没时间了。得出去开会了,哎。
晚上有时间来研究。这个我很有兴趣
[/Quote]

你好,请问你会解决吗,帮我看一下吧
wzca 2012-04-11
  • 打赏
  • 举报
回复
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
害死人啊

用WebBrowers 应该是个好注意

没时间了。得出去开会了,哎。
晚上有时间来研究。这个我很有兴趣
wzca 2012-04-11
  • 打赏
  • 举报
回复
看错了。原来是个 iframe . 再看看。应该不难
wzca 2012-04-11
  • 打赏
  • 举报
回复
刚看了一下,还真有点意思。读过来的内容片段如下:
<form target="_blank" name="print_form" action="/buxus/lib/print_page/print_page.php" method="post">
<input type="hidden" name="CONTAINER" value="print_this">
<input type="hidden" name="HEAD" value="1">
<input type="hidden" name="AUTO_BACK" value="0">
<input type="hidden" name="COLORS" value="1">
<input type="hidden" name="FOOTERS" value="1">
<input type="hidden" name="UNLINK_FILE" value="0">
<input type="hidden" name="TITLE_FILE_NAME" value="1">
<input type="hidden" name="CHARSET" value="1">
<input type="hidden" name="CSS" value="">
<input type="hidden" name="FILE" value="http://www.eset.eu/download/ess-trial-form">
<input type="hidden" name="PRINT_KEY" value="bb19836a92742993d38cb8d98fee321085e7857d">

</form>

通过IE的运算后。。。。就成了这样
      <form name="s62719e3f4367adc561d71c98a1cd7d98" method="post" action="./">
<div id="s60969a16eaa0c241ed5156a172308ec8">Email.: </div>
<div id="sbb0c333c1d3e3e00888d3814eba6c27b"><input type="text" name="sbb0c333c1d3e3e00888d3814eba6c27b" size="46" maxlength="138" value=""/></div>
<div id="s9b604ed6ece81f412d652570ea3f9912"><input type="text" name="s9b604ed6ece81f412d652570ea3f9912" size="31" maxlength="143" value=""/></div>
<div id="s817ff65d94f84a29b5db32a633d955e3"><input type="text" name="s817ff65d94f84a29b5db32a633d955e3" size="42" maxlength="123" value=""/></div>
<div id="s174afb895631d37fb0f4f55c63543128"><input type="text" name="s174afb895631d37fb0f4f55c63543128" size="38" maxlength="127" value=""/></div>
<div id="sf80a22351a9239b5b07183775f463e57"><input type="text" name="sf80a22351a9239b5b07183775f463e57" size="21" maxlength="136" value=""/></div>
<div id="s7aaea299f314ef3345bdc5c9cbc7ec08"><input type="text" name="s7aaea299f314ef3345bdc5c9cbc7ec08" size="45" maxlength="146" value=""/></div>
<div id="sb2378f4268b4a53f1367f4e437cc6663"><input type="text" name="sb2378f4268b4a53f1367f4e437cc6663" size="15" maxlength="127" value=""/></div>
<div id="s3248e552a551f7edc2bb7da6d41b9d2b"><input type="text" name="s3248e552a551f7edc2bb7da6d41b9d2b" size="48" maxlength="121" value=""/></div>
<div id="s30a5e38706de4bb6751284435fb5013a"><input type="text" name="s30a5e38706de4bb6751284435fb5013a" size="35" maxlength="124" value=""/></div>
<div id="saa260b959b369b1124af2681bd5c90b0"><input type="text" name="saa260b959b369b1124af2681bd5c90b0" size="46" maxlength="133" value=""/></div>
<div id="sced60747bffa27fefb179c5b431d63ac"><input type="text" name="sced60747bffa27fefb179c5b431d63ac" size="41" maxlength="130" value=""/></div>
<div id="sa17ac6bb02dd4d33257d266589a09861"><input type="text" name="sa17ac6bb02dd4d33257d266589a09861" size="41" maxlength="147" value=""/></div>
<div id="email"><input type="text" name="email" size="27" maxlength="144" value=""/></div>
<div id="mail"><input type="text" name="mail" size="26" maxlength="146" value=""/></div>
<div id="sd1aad8b2d669fadb089ad0b931aec3b8"><input type="text" name="sd1aad8b2d669fadb089ad0b931aec3b8" size="36" maxlength="120" value=""/></div>
<div id="sa9f041ff1c96bbde3200e7aa91db3d9b"><input type="text" name="sa9f041ff1c96bbde3200e7aa91db3d9b" size="21" maxlength="146" value=""/></div>
<div id="s70871397bcbf01996f9ccd3def463d7c"><input type="submit" name="s92a2f84027e2f3f19e34e63361e196f7" value="Submit"/></div>
<input type="hidden" name="s9ed1d223cf3680f8ce4a86632f52161f" value="sd1ea7b91bd270a1a318e62fc3aeffcd5"/>
</form>


用idHttp 取过来,明显有问题, 我再研究研究
cnotes 2012-04-09
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 的回复:]

引用 9 楼 的回复:

引用 8 楼 的回复:

先Get这个页面,把上面的参数和值都复制下来,再Post


真正提交的不是这一段吗?

HTML code
<div id="s5fa6a4ba7f0740f07af40403ba75eda4"><input type="submit" name="sdf513135f9abd11a475c465e879cf86f" ……
[/Quote]

是啊 你能不能帮我写一下啊 链接是前面那个http://www.eset. eu/download/ess-trial-form 如果提交成功的话会发送一封邮件到邮箱的
cdchq 2012-04-09
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

引用 8 楼 的回复:

先Get这个页面,把上面的参数和值都复制下来,再Post


真正提交的不是这一段吗?

HTML code
<div id="s5fa6a4ba7f0740f07af40403ba75eda4"><input type="submit" name="sdf513135f9abd11a475c465e879cf86f" value="Submit"/>……
[/Quote]
是这一段
提交时,<form>和</form>之间的每个input及其值,都是post参数之一
你很多基础知识都不知道,估计要写出这个程序来,还要折腾段时间,呵呵
cnotes 2012-04-09
  • 打赏
  • 举报
回复
Exception class EIdHTTPProtocolException with message 'HTTP/1.1 400 Bad Request'.
cnotes 2012-04-09
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

先Get这个页面,把上面的参数和值都复制下来,再Post
[/Quote]

真正提交的不是这一段吗?

<div id="s5fa6a4ba7f0740f07af40403ba75eda4"><input type="submit" name="sdf513135f9abd11a475c465e879cf86f" value="Submit"/></div>
<input type="hidden" name="s49894cd6ae2b08965ecc282915e326a3" value="s411d608ba62e1c2f03125e6c109834c9"/>
cdchq 2012-04-09
  • 打赏
  • 举报
回复
先Get这个页面,把上面的参数和值都复制下来,再Post
cnotes 2012-04-09
  • 打赏
  • 举报
回复
    <div id="s979957548ba7befdcbfeffb47eaa6b0a">
<form name="s8fb24e08b92e7cfda372a3b82a5e17dd" method="post" action="./">
<div id="s6950fbf6786c851fddb6e9658b016327">Email.: </div> <div id="se1f2977ce70b81a4c2f6b0098969a9b6"><input type="text" name="se1f2977ce70b81a4c2f6b0098969a9b6" size="44" maxlength="141" value=""/></div>
<div id="s07fdc6f9f8b88ce704d314c43878c369"><input type="text" name="s07fdc6f9f8b88ce704d314c43878c369" size="38" maxlength="141" value=""/></div>
<div id="s4ee9e5f3d52427e0fbe557d171cca33d"><input type="text" name="s4ee9e5f3d52427e0fbe557d171cca33d" size="45" maxlength="143" value=""/></div>
<div id="sdae704fde06424b06c4dc36b18596f8f"><input type="text" name="sdae704fde06424b06c4dc36b18596f8f" size="49" maxlength="149" value=""/></div>
<div id="sc4594b618f71c947a4e52e18d4916f73"><input type="text" name="sc4594b618f71c947a4e52e18d4916f73" size="14" maxlength="150" value=""/></div>
<div id="se09ba6ead6c12f48daedfb9783263a0b"><input type="text" name="se09ba6ead6c12f48daedfb9783263a0b" size="17" maxlength="126" value=""/></div>
<div id="sa0999a6a085c7b1fb437170e4d4dd8e9"><input type="text" name="sa0999a6a085c7b1fb437170e4d4dd8e9" size="13" maxlength="127" value=""/></div>
<div id="s6577ab912bdaed8488df5b0d211af121"><input type="text" name="s6577ab912bdaed8488df5b0d211af121" size="37" maxlength="140" value=""/></div>
<div id="s4649849ad176b86659bdbc4275d94c93"><input type="text" name="s4649849ad176b86659bdbc4275d94c93" size="46" maxlength="134" value=""/></div>
<div id="scb7f4d4f9cbc9620816eea99db9fcd56"><input type="text" name="scb7f4d4f9cbc9620816eea99db9fcd56" size="35" maxlength="138" value=""/></div>
<div id="s07d21d8a8fff9f6fd801583a861416dd"><input type="text" name="s07d21d8a8fff9f6fd801583a861416dd" size="16" maxlength="146" value=""/></div>
<div id="email"><input type="text" name="email" size="45" maxlength="140" value=""/></div>
<div id="sd0dfcf2491a19ea75d82e0d6dbec4bcb"><input type="text" name="sd0dfcf2491a19ea75d82e0d6dbec4bcb" size="48" maxlength="135" value=""/></div>
<div id="sf5e327f97e6c356fb8777f3ac1d4e336"><input type="text" name="sf5e327f97e6c356fb8777f3ac1d4e336" size="18" maxlength="149" value=""/></div>
<div id="mail"><input type="text" name="mail" size="43" maxlength="143" value=""/></div>
<div id="sa69a3831987b7a9a7ed058f940ad52fc"><input type="text" name="sa69a3831987b7a9a7ed058f940ad52fc" size="38" maxlength="121" value=""/></div>
<div id="s5fa6a4ba7f0740f07af40403ba75eda4"><input type="submit" name="sdf513135f9abd11a475c465e879cf86f" value="Submit"/></div>
<input type="hidden" name="s49894cd6ae2b08965ecc282915e326a3" value="s411d608ba62e1c2f03125e6c109834c9"/>
</form>
</div>

</body>
</html>


这段变量什么应该为什么?
cnotes 2012-04-09
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

""is invalid integer的错误提示,这不就是错误提示吗?应该是你输入的值本身就不是整型导致的吧。或者是你没有传这个值,但你的网站用Request.Form("xxx")进行了类型转换,则出错。此时也应该给个默认值的。

网页如果是asp.net的话用的是Request.Form("xxx")来接收的,跟你所用的语言有关吧,很久没弄过网站了,记不清了,自己试试便知.
[/Quote]

http://www.eset. eu/download/ess-trial-form

这个地址 我怎么post都不成功。。奇怪了。。可以的话就结贴了!
shuaialang 2012-04-09
  • 打赏
  • 举报
回复
fastnet
nmhttp
不支持https
cdchq 2012-04-09
  • 打赏
  • 举报
回复
1.is invalid integer是delphi中出现的?还是网页源码中出现的?
如果是delphi中出现的,应该是你把Int类型的变量直接Post,这样不行的。Post出去的数据,都要转化成字符串,再Post。例如:

sPost:=TStringStream.Create('');
try
sPost.WriteString('username='+'你的名字'+'&'+
'password='+'你的密码'+'&'+
);
try
sHtml:=IdHTTP1.Post('http://www.123.com',sPost);
except
end;
finally
sPost.Free;
end;


2.post成功后,网页上显示的东西一般来说肯定和没post成功时不一样。比如会显示"登录成功"之类的。上面的代码中
sHtml:=IdHTTP1.Post('http://www.123.com',sPost);
sHtml就是Post后,服务器返回的网页源码。在其中查找,如果有"登录成功"这几个字,就表示你post成功了,反之则失败。

3.还有个ICS控件,和Indy类似。里面的httpCl控件对应indy中的Idhttp控件。indy是阻塞模式,ICS可以用非阻塞模式。使用上大同小异。
加载更多回复(3)

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧