IdHTTP post 数据的问题.
用IdHTTP控件向一个网站提交数据,达到留言的功能.没有成功.
/////////////////////////////////////////////////////////////////////////
用HttpWatch 监视IE中我自己的账号向我自己的页面发表留言时的数据如下(网址用xxxxx代替)
流标签的内容
发送的:
POST /gossip.do 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, */*
Referer: http://xxxxx.com/getuser.do?id=42531288
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)
Host: xxxxx.com
Content-Length: 58
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: cookieuniv=3002; __utma=204579609.1582353597.1168328182.1168331565.1168331780.7; __utmb=204579609; __utmz=204579609.1168328182.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); wh_email=weixing979@163.com; wh_key=a65cf3dfa63ba2297ebda4e86e6c9702; email=weixing979@163.com; password=95307607428ce336e2da99049fe41262; mop_uniq_ckid=218.9.160.142_1168329779_1721375101; societyid=6c202d413ed572e4cc4164a8e76912fe116eae775a6a294a; JSESSIONID=abcm0HjDU1fcp7k8bagar; __utmc=204579609
curpage=&from=main&id=42531288&cc=42531288&body=1234567890
接收到的:
HTTP/1.1 302 Found
Server: Resin/3.0.21
Vary: Accept-Encoding
Location: http://xxxxx.com/getuser.do?id=42531288&#starttalk
Content-Type: text/html
Content-Length: 90
Connection: close
Date: Tue, 09 Jan 2007 08:36:45 GMT
The URL has moved <a href= "http://xxxxx.com/getuser.do?id=42531288&#starttalk "> here </a>
摘要标签的内容:
提交表单浏览器提交值到 http://xxxxx.com/gossip.do Completed
Started At2007-Jan-09 16:36:48.718 (local time) Completed
Connect连接到 IP 地址 'XX.XX.XXX.XXX ' Completed
HTTP Request无条件发送此请求 http://xxxxx.com/gossip.do Completed
HTTP Response返回标题和内容 Completed
改向 改向到 http://xxxxx.com/getuser.do?id=42531288&#starttalk 由服务器造成
/////////////////////////////////////////////////////////////////////////
网页中留言部分的代码
<form id= "leaveWordForm " method= "post " action= "/gossip.do " onsubmit= "timeout();return gbtextval(); ">
<p id= "starttalk "> <input type= "button " id= "starttalkBtn " class= "subbutton " value= "我要留言 " onclick= "showLayer( 'starttalkForm ');getEl( 'starttalk ').style.display= 'none ';visible=true;getEl( 'cmtbody ').focus(); " /> </p>
<div id= "starttalkForm " style= "display:none; ">
<p>
<input type= "submit " value= "留言 " class= "subbutton " id= "editorFormBtn " tabindex= "2 " />
<span class= "discription "> (每条最多2000字) </span>
<input type= "button " value= "取消 " class= "inputbutton " onclick= "cancelLeaveWord() " tabindex= "3 " />
<input type= "hidden " name= "curpage " value= " " />
<input type= "hidden " name= "from " value= "main " />
<input type= "hidden " name= "id " value= "42531288 " />
<input type= "hidden " name= "cc " id= "leaveWordTo " value= "42531288 " />
</p>
<textarea id= "cmtbody " name= "body " cols= "100% " rows= "6 " tabindex= "1 " onfocus= "focusAction(event) "> </textarea>
</div>
</form>
/////////////////////////////////////////////////////////////////////////
BCB程序的发送代码:
IdHTTP1-> Request-> ExtraHeaders-> Values[ "cookie "] = cookie;
IdHTTP1-> HandleRedirects = true;
IdHTTP1-> Request-> Referer = "http://xxxxx.com/getuser.do?id=42531288 ";
IdHTTP1-> Request-> AcceptLanguage = "zh-cn ";
IdHTTP1-> Request-> ContentType = "application/x-www-form-urlencoded ";
IdHTTP1-> Request-> AcceptEncoding = "gzip, deflate ";
IdHTTP1-> Request-> UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322) ";
IdHTTP1-> Host = "xxxxx.com ";
IdHTTP1-> Request-> ContentLength = 58;
IdHTTP1-> Request-> Connection = "Keep-Alive ";
AnsiString url = "http://xxxxx.com/gossip.do ";
TStrings* tData=new TStringList();
TStringStream* stream=new TStringStream( " ");
tData-> Add( "curpage= ");
tData-> Add( "from=main ");
tData-> Add( "id=42531288 ");
tData-> Add( "cc=42531288 ");
tData-> Add( "body=1234567890 ");
IdHTTP1-> Post(url,tData,stream);
Memo1-> Text = stream-> DataString;
用这些代码没有发送成功. 另外BCB中用到的cookie是我在程序中放了一个CppWebBrowser,登录后获得的cookie,用这个cookie可以Get出正确的页面.
大家看一下是什么问题
[解决办法]
Indy最好用9.0.1X以上的!
用WebAppDebugger处理,必要时修改Indy源码
[解决办法]
以前也碰到过同样问题
[解决办法]
mark一下,偶马上也要做相关的东东了,到时交流一下哈