★★★ 高分求助!我的idHttp为什么不能提交数据到表单? 大哥大姐看看吧(100)

  • 主题发起人 主题发起人 jozosoft
  • 开始时间 开始时间
J

jozosoft

Unregistered / Unconfirmed
GUEST, unregistred user!
我的idHttp为什么不能提交数据到表单? 一、待填写表单说明: 当前URL名称: www.139.com/thread.php?fid-22.html Form代码: <form name="FORM" method="post" action="post.php?" enctype = "multipart/form-data" onsubmit="return checkpost(document.FORM);" id="anchor"> <input type="text" class="input" id="atc_title" name="atc_title" value="" size="55" /> <input type="hidden" name="atc_autourl" value="1" /> </div> <textarea onkeydown="quickpost(event)" name="atc_content" id="atc_content" rows="8" style="width:96%"> </textarea> </form> 二、我的思路及代码 1、用IdHttp先登录,这一步成功了 测试标准:我访问一个需登录才能访问的网页,能正常访问 2、我的代码(局部) var ResponseStream: TMemoryStream; MultiPartFormDataStream: TMsMultiPartFormDataStream; begin MultiPartFormDataStream := TMsMultiPartFormDataStream.Create; ResponseStream := TMemoryStream.Create; // FHttp.Request.ContentType :='multipart/form-data'; // MultiPartFormDataStream.RequestContentType; // FHttp.Request.ContentType := 'multipart/form-data;boundary=---------------------------7d928035300b0'; FHTTP.HTTPOptions:=[hoForceEncodeParams]; FHTTP.ProtocolVersion := pv1_1; FHTTP.Request.Accept:='*/*'; FHTTP.Request.Referer:='http://www.139.com/post.php?fid=24'; FHTTP.Request.AcceptLanguage := 'zh-cn'; FHTTP.Request.ContentType := 'multipart/form-data; boundary=---------------------------7d928035300b0'; FHTTP.Request.AcceptEncoding := 'gzip, deflate'; FHTTP.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)'; FHTTP.Request.Host := 'www.139.com'; FHTTP.Request.ContentLength :=3614 ; //MultiPartFormDataStream.Size;// length(Edit1.Text); FHTTP.Request.Connection := 'Keep-Alive'; FHTTP.Request.CacheControl := 'no-cache'; MultiPartFormDataStream.AddFormField('magicname', ''); MultiPartFormDataStream.AddFormField('magicid', ''); MultiPartFormDataStream.AddFormField('verify', '6b790d3c'); MultiPartFormDataStream.AddFormField('p_type', '16'); MultiPartFormDataStream.AddFormField('atc_title', '111002'); MultiPartFormDataStream.AddFormField('atc_iconid', '0'); MultiPartFormDataStream.AddFormField('ctype[best]', 'money'); MultiPartFormDataStream.AddFormField('bonus[best]', ''); ////////////////// MultiPartFormDataStream.AddFormField('ctype[active]', 'money'); MultiPartFormDataStream.AddFormField('bonus[active]', ''); MultiPartFormDataStream.AddFormField('atc_content', 'I am the content'); MultiPartFormDataStream.AddFormField('topped', '0'); MultiPartFormDataStream.AddFormField('atc_autourl', '1'); MultiPartFormDataStream.AddFormField('atc_usesign', '1'); MultiPartFormDataStream.AddFormField('atc_convert', '1'); MultiPartFormDataStream.AddFile('attachment_1' , ';c:/abc.txt','text/plain') ; //添加文件 //MultiPartFormDataStream.AddFile('attachment_1' , 'c:/abc.txt','application/octet-stream') ; //这样试过也不行 MultiPartFormDataStream.AddFormField('atc_desc1', ''); MultiPartFormDataStream.AddFormField('att_special1', '0'); MultiPartFormDataStream.AddFormField('att_ctype1', 'money'); MultiPartFormDataStream.AddFormField('atc_needrvrc1', '0'); // MultiPartFormDataStream.AddFormField('attachment_2', '; filename=', '', 'Content-Type: application/octet-stream'); // 文件名为空时,会提示无法找到此文件 // MultiPartFormDataStream.AddFile('attachment_2' , 'c:/123.txt' ,'text/plain') ; // MultiPartFormDataStream.AddFormField('attachment_2','c:/abc.txt'); //MultiPartFormDataStream.AddFile('attachment_2' , 'c:/123.txt' ,'application/octet-stream') ; MultiPartFormDataStream.AddFormField('atc_desc2', ''); MultiPartFormDataStream.AddFormField('att_special2', '0'); MultiPartFormDataStream.AddFormField('att_ctype2', 'money'); MultiPartFormDataStream.AddFormField('atc_needrvrc2', '0'); MultiPartFormDataStream.AddFormField('atc_tags', ''); MultiPartFormDataStream.AddFormField('step', '2'); MultiPartFormDataStream.AddFormField('pid', ''); MultiPartFormDataStream.AddFormField('action', 'new'); MultiPartFormDataStream.AddFormField('fid', '24'); MultiPartFormDataStream.AddFormField('tid', '0'); MultiPartFormDataStream.AddFormField('article', '0'); MultiPartFormDataStream.AddFormField('special', '3'); MultiPartFormDataStream.AddFormField('_hexie', 'ca14e4d8'); MultiPartFormDataStream.PrepareStreamForDispatch; // FHTTP.Request.ContentLength := 3614; MultiPartFormDataStream.Size;// length(Edit1.Text); MultiPartFormDataStream.Position := 0; //调用idhttp的post方法,第一个参数是用于处理上载form的asp/php等等脚本,第三个是接收脚本执行完成后的返回内容) FHttp.Post('http://www.139.com/post.php', MultiPartFormDataStream, ResponseStream); //非法操作 //因为不知道到底提交给哪个文件,故试了多个文件,但最终一查发表过的帖子,都没有成功。 FHttp.Post('http://www.139.com/post.php?fid=24', MultiPartFormDataStream, ResponseStream); ResponseStream.SaveToFile('c:/stream3.txt'); FHttp.Post('http://www.139.com/thread.php?fid=24', MultiPartFormDataStream, ResponseStream); ResponseStream.SaveToFile('c:/stream4.txt'); FHttp.Post('http://www.139.com/thread.php?', MultiPartFormDataStream, ResponseStream); ResponseStream.SaveToFile('c:/stream5.txt'); FHttp.Post('http://www.139.com/thread.php', MultiPartFormDataStream, ResponseStream); ResponseStream.SaveToFile('c:/stream6.txt'); MultiPartFormDataStream.SaveToFile('c:/all.txt'); MultiPartFormDataStream.SaveToFile('c:/1.txt'); MultiPartFormDataStream.Free; ResponseStream.Free; 三、说明点 1、我为什么不用WebBrowser? 答:我用了,能正常发贴子,但是无法上传附件。 2、原网页上传文件时,是通过一个js脚本来上传的,在当前要填写的form上没有显式地显示控件 。 3、我试过用网络包监视工具来监视数据,以下是监视到的信息: POST /post.php? HTTP/1.1 Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */* Referer: http://www.139.com/post.php?fid=24 Accept-Language: zh-cn Content-Type: multipart/form-data; boundary=---------------------------7d928035300b0 Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) Host: www.139.com Content-Length: 3614 Connection: Keep-Alive Cache-Control: no-cache Cookie: 20ac2_lastpos=other; 20ac2_ol_offset=194; 20ac2_threadlog=%2C23%2C24%2C; 20ac2_readlog=%2C1851%2C1853%2C1854%2C1866%2C1867%2C1868%2C1869%2C1916%2C; 20ac2_winduser=AVNqDgVaVAYDWAUAVAEFUVZXB1dVWg9dAFZRVgcFAV0DUV5r; 20ac2_ck_info=%2F%09; 20ac2_lastvisit=3811%091257486060%09%2Fpost.php%3Ffid%3D24; lstat_bc_772800=27821968222999282857; lstat_ss_772800=6_1257514865_382310928 -----------------------------7d928035300b0 Content-Disposition: form-data; name="magicname" -----------------------------7d928035300b0 Content-Disposition: form-data; name="magicid" -----------------------------7d928035300b0 Content-Disposition: form-data; name="verify" 6b790d3c -----------------------------7d928035300b0 Content-Disposition: form-data; name="p_type" 16 -----------------------------7d928035300b0 Content-Disposition: form-data; name="atc_title" 111002 -----------------------------7d928035300b0 Content-Disposition: form-data; name="atc_iconid" 0 -----------------------------7d928035300b0 Content-Disposition: form-data; name="ctype[best]" money -----------------------------7d928035300b0 Content-Disposition: form-data; name="bonus[best]" -----------------------------7d928035300b0 Content-Disposition: form-data; name="ctype[active]" money -----------------------------7d928035300b0 Content-Disposition: form-data; name="bonus[active]" -----------------------------7d928035300b0 Content-Disposition: form-data; name="atc_content" I am the content -----------------------------7d928035300b0 Content-Disposition: form-data; name="topped" 0 -----------------------------7d928035300b0 Content-Disposition: form-data; name="atc_autourl" 1 -----------------------------7d928035300b0 Content-Disposition: form-data; name="atc_usesign" 1 -----------------------------7d928035300b0 Content-Disposition: form-data; name="atc_convert" 1 -----------------------------7d928035300b0 Content-Disposition: form-data; name="attachment_1"; filename="C:/abc.txt" Content-Type: text/plain I am Attach File -----------------------------7d928035300b0 Content-Disposition: form-data; name="atc_desc1" -----------------------------7d928035300b0 Content-Disposition: form-data; name="att_special1" 0 -----------------------------7d928035300b0 Content-Disposition: form-data; name="att_ctype1" money -----------------------------7d928035300b0 Content-Disposition: form-data; name="atc_needrvrc1" 0 -----------------------------7d928035300b0 Content-Disposition: form-data; name="attachment_2"; filename="" Content-Type: application/octet-stream -----------------------------7d928035300b0 Content-Disposition: form-data; name="atc_desc2" -----------------------------7d928035300b0 Content-Disposition: form-data; name="att_special2" 0 -----------------------------7d928035300b0 Content-Disposition: form-data; name="att_ctype2" money -----------------------------7d928035300b0 Content-Disposition: form-data; name="atc_needrvrc2" 0 -----------------------------7d928035300b0 Content-Disposition: form-data; name="atc_tags" -----------------------------7d928035300b0 Content-Disposition: form-data; name="step" 2 -----------------------------7d928035300b0 Content-Disposition: form-data; name="pid" -----------------------------7d928035300b0 Content-Disposition: form-data; name="action" new -----------------------------7d928035300b0 Content-Disposition: form-data; name="fid" 24 -----------------------------7d928035300b0 Content-Disposition: form-data; name="tid" 0 -----------------------------7d928035300b0 Content-Disposition: form-data; name="article" 0 -----------------------------7d928035300b0 Content-Disposition: form-data; name="special" 3 -----------------------------7d928035300b0 Content-Disposition: form-data; name="_hexie" ca14e4d8 -----------------------------7d928035300b0-- 其它: 我的idHttp.AllowCookies是 True了。 我的程序发送前,里面的包也和它相同了(除了包的头里面有些不同之外,如cookies,但我的程序登录是没问题了的),但服务器那边的已发帖子还是没有我的数据。 这样看我的帖子可能有点儿多,如果要源代码,我另行传送。非常谢谢各位。
 
后退
顶部