delphi idhttp post 网页

linzhen6790 2012-09-03 01:53:32
用httpwath 抓包工具下来的提交数据

POST /login.php?forward=http%3A%2F%2Fmy.2345.com HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, */*
Referer: http://login.2345.com/login.php?forward=http%3A%2F%2Fmy.2345.com
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; QQDownload 714)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: login.2345.com
Content-Length: 135
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: goHd=; site_str=; localNav=; lastLogin=; sts=1; lc2=54511; wc=54511; lc=54511; wc_n=%25u5317%25u4EAC; gy=setM%2ClastLogin2012-9-3%252013%253A9%253A29%2C; name_ie=%25115%25121%25115%25116%25101%25109%25116%25101%25115%25116; validatenum=8b519f198dd26772e3e82874826b04aa; email=localhhost@localhost.localhost; ggbd=0; code_str=; mystyle_display=; theme=0; theme_logo=0; wc_sf=; __utma=62515951.1042536828.1346641565.1346641565.1346641565.1; __utmz=62515951.1346641565.1.1.utmcsr=2345.com|utmccn=(referral)|utmcmd=referral|utmcct=/; finished_online1161895=1; zcValue_u=08d017227bb3ec0145e88cebd20e9da4; zcValue_lo=4a584ce72b09f1b7f0c538b3a8bd9b28; iden=89c50900e524d1607f9ce370de255c44; PHPSESSID=ec1d3t12ruppmaell3obf44gq4; validatenum=046ddf96c233a273fd390c3d0b1a9aa4

cmd=login&forward=http%3A%2F%2Fmy.2345.com&password=54b53072540eeeb8f8e9343e71f28176&username=systemtest&pwd=system&check_code=&button=


代码
procedure TForm1.Button2Click(Sender: TObject);
Var
Response:string;
Paramstr:Tstringlist;
IdHTTP1:Tidhttp;
begin
IdHTTP1:=Tidhttp.create(nil);
Paramstr:= TStringList.Create;
Paramstr.Add('username=system');
Paramstr.Add('password=systemtest');

IdHTTP1.Request.Referer := 'http://login.2345.com/login.php?forward=http%3A%2F%2Fmy.2345.com';
IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
IdHTTP1.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; QQDownload 714)';
IdHttp1.Request.SetHeaders;
IdHttp1.Request.CustomHeaders.add('Cookie: goHd=; site_str=; localNav=; lastLogin=; sts=1; lc2=54511; wc=54511; lc=54511; wc_n=%25u5317%25u4EAC; gy=setM%2ClastLogin2012-9-3%252013%253A9%253A29%2C;');
IdHttp1.Request.CustomHeaders.add(' name_ie=%25115%25121%25115%25116%25101%25109%25116%25101%25115%25116; validatenum=8b519f198dd26772e3e82874826b04aa; email=localhhost@localhost.localhost; ggbd=0; ');
IdHttp1.Request.CustomHeaders.add('code_str=; mystyle_display=; theme=0; theme_logo=0; wc_sf=;');
IdHttp1.Request.CustomHeaders.add(' __utma=62515951.1042536828.1346641565.1346641565.1346641565.1; __utmz=62515951.1346641565.1.1.utmcsr=2345.com|utmccn=(referral)|utmcmd=referral|utmcct=/;');
IdHttp1.Request.CustomHeaders.add(' finished_online1161895=1; zcValue_u=08d017227bb3ec0145e88cebd20e9da4; zcValue_lo=4a584ce72b09f1b7f0c538b3a8bd9b28; iden=89c50900e524d1607f9ce370de255c44;');
IdHttp1.Request.CustomHeaders.add(' PHPSESSID=ec1d3t12ruppmaell3obf44gq4; validatenum=046ddf96c233a273fd390c3d0b1a9aa4');
IdHttp1.Request.CustomHeaders.add('cmd=login&forward=http%3A%2F%2Fmy.2345.com&password=54b53072540eeeb8f8e9343e71f28176&username=systemtest&pwd=system&check_code=&button=');
Response:=IdHTTP1.Post('http://login.2345.com/login.php?forward=http%3A%2F%2Fmy.2345.com', Paramstr);
showmessage(Response);
Freeandnil(IdHTTP1);
Paramstr.Free;

end;

提交总是不成功

测试账号:system
测试密码:systemtest
测试网址:http://login.2345.com/login.php?forward=http%3A%2F%2Fmy.2345.com

...全文
2109 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
znhyz1 2013-10-17
  • 打赏
  • 举报
回复
我的老提示400 Bad Request!!!

procedure TFrmMain.btnLoginClick(Sender: TObject);
var
  resParams: TStringStream;
  postParams: TStringList;
begin
  btnLogin.Enabled := False;
  resParams := TStringStream.Create('');
  postParams := TStringList.Create;
  try
    mmLog.Lines.Clear;
    IdHTTP.Request.CacheControl :='no-cache';
    IdHTTP.Request.Connection :='Keep-Alive';
    IdHTTP.Request.Accept :='text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
    IdHTTP.Request.ContentType :='application/x-www-form-urlencoded';
    IdHTTP.Request.AcceptCharSet := 'UTF-8';
    IdHTTP.Request.AcceptEncoding := 'UTF-8';
    IdHTTP.Request.AcceptLanguage := 'UTF-8';
    IdHTTP.HandleRedirects :=True;  //允许重定向,因为这个站点会发生重定向
    IdHTTP.AllowCookies :=True;
    IdHTTP.HTTPOptions :=[hoForceEncodeParams];
    postParams.Clear;
    postParams.Add('account=znhj');
    postParams.Add('password=012250');
    //postParams.Add('url=/console/remote/');
    resParams.WriteString('');
    IdHTTP.Request.Referer :='https://sunlogin.oray.com/passport/login?lang=zh_CN';   //设置来路,此网站要求
    IdHTTP.Post('https://sunlogin.oray.com/passport/login',postParams,resParams);
    mmLog.Lines.Add(Utf8ToAnsi(resParams.DataString));
  finally
    resParams.Free;
    postParams.Free;
    btnLogin.Enabled := True;
  end;
end;
lszxyxl 2013-05-03
  • 打赏
  • 举报
回复
是怎样解决的呢?能发下解决后成功的代码吗?
wzca 2012-09-10
  • 打赏
  • 举报
回复
我写的东西都没啦???
大约的意思是
POST 数据过去可以成功了,但是返回一大堆的JS,要在本地执行,会写一大堆的Cookie
JS里会再嵌进来一人 common.js
写完Cookie后,会调用一个正常的链接,进入主页,
这页要读上面设置的Cookie
需要研究下,怎么执行本地的JaveScript.有点麻烦
wzca 2012-09-10
  • 打赏
  • 举报
回复

应该可以了。嘿嘿
http://my.csdn.net/my/code/detail/18587
linzhen6790 2012-09-08
  • 打赏
  • 举报
回复
我也只能看到6楼
linzhen6790 2012-09-07
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]
请问,你的额外难题解决了吗?
[/Quote]
哪一个难题呢?listbox 循环 停止?
科多兽 2012-09-07
  • 打赏
  • 举报
回复
请问,你的额外难题解决了吗?
wzca 2012-09-06
  • 打赏
  • 举报
回复
刚想起来,明天11点才走,早上应该没啥事,
如果我还记得的话,就来帮你试一下。
wzca 2012-09-06
  • 打赏
  • 举报
回复
这个其实很容易的,你是不“第一次”啊。嘿嘿
这两天太忙, 下星期一没事给你写个例子呗(如果你能等到那时候的话)
明天又要出门了。哎。天生的命苦啊。
wzca 2012-09-06
  • 打赏
  • 举报
回复
我只能看到6楼的,其它的都没了? 怪事啊
wzca 2012-09-06
  • 打赏
  • 举报
回复
内容过长????

storeUtil.init()


s_cookie("lastLogin","2012-09-06%2011%3A29%3A55",604800,"/","2345.com");
s_cookie("integral","",604800,"/","2345.com");
s_cookie({store:"cookie"},"name_ie","%115%121%115%116%101%109%49",604800,"/","2345.com");
s_cookie({store:"cookie"},"user_info","ZmM1Zk1kbWI0amlrTXJkWElrWjIyQUN3a2NFUlNwelIrLzNBSCtFVGwxVkNZdWFva2ZpdXJPL1lnN0NqQ3c=",604800,"/","2345.com");
s_cookie("user_info","ZmM1Zk1kbWI0amlrTXJkWElrWjIyQUN3a2NFUlNwelIrLzNBSCtFVGwxVkNZdWFva2ZpdXJPL1lnN0NqQ3c=",604800,"/","2345.com");
s_cookie("validatenum","a4ed074907dc9bc3c86cc52904d763e3",604800,"/","2345.com");

s_cookie({store:"cookie"},"passid","3459582",604800,"/","2345.com");
s_cookie({store:"cookie"},"validatenum","a4ed074907dc9bc3c86cc52904d763e3",604800,"/","2345.com");
s_cookie({store:"cookie"},"uid","4024627",604800,"/","2345.com");
s_cookie({store:"cookie"},"u_sec","3b1e0242582a1b75f5a4629b123ad014|7e099c513c89b404d6866ddf00f0471e",604800,"/","2345.com");
s_cookie({store:"cookie"},"name","system1",604800,"/","2345.com");
s_cookie({store:"cookie"},"email","localhhost@localhost.localhost",604800,"/","2345.com");
s_cookie({store:"cookie"},"iden","3659a530c228b3a0ac4e24f31df533d8",604800,"/","2345.com");

s_cookie("skin","0",604800,"/","2345.com");
s_cookie("skinz","0",604800,"/","2345.com");
s_cookie("bgid","0",604800,"/","2345.com");
s_cookie({store:"cookie"},"ggbd","0",604800,"/","2345.com");
s_cookie("code_str","",604800,"/","2345.com");
s_cookie({store:"cookie"},"code_str","",604800,"/","2345.com");
s_cookie("bgurl","",604800,"/","2345.com");
s_cookie({store:"cookie"},"localNav","null",604800,"/","2345.com");
s_cookie("localNav","null",604800,"/","2345.com");
s_cookie({store:"cookie"},"mystyle_display","",604800,"/","2345.com");
s_cookie("mystyle_display","",604800,"/","2345.com");
s_cookie("fl","0",604800,"/","2345.com");
s_cookie({store:"cookie"},"theme","0",604800,"/","2345.com");
s_cookie("theme","0",604800,"/","2345.com");
s_cookie({store:"cookie"},"theme_logo","0",604800,"/","2345.com");
s_cookie("theme_logo","0",604800,"/","2345.com");

s_cookie({store:"cookie"},"lc","54511",604800,"/","2345.com");
s_cookie("lc","54511",604800,"/","2345.com");
s_cookie({store:"cookie"},"wc","54511",604800,"/","2345.com");
s_cookie("wc","54511",604800,"/","2345.com");
s_cookie({store:"cookie"},"wc_n","%u5317%u4EAC",604800,"/","2345.com");
s_cookie("wc_n","%u5317%u4EAC",604800,"/","2345.com");
s_cookie({store:"cookie"},"wc_sf","",604800,"/","2345.com");
s_cookie("wc_sf","",604800,"/","2345.com");s_cookie("site_str","http://www.iqiyi.com/^^%u7231%u5947%u827A%u9AD8%u6E05^^1^^1347104840890^^1,",604800,"/","2345.com");
s_cookie({store:"cookie"},"site_str","http://www.iqiyi.com/^^%u7231%u5947%u827A%u9AD8%u6E05^^1^^1347104840890^^1,",604800,"/","2345.com");window.location.href="http://bbs.2345.com/api/passport.php?action=login&cookieTime=604800&auth=&forward=http%3A%2F%2Fmy.2345.com&verify="
</script>
wzca 2012-09-06
  • 打赏
  • 举报
回复
Post数据过去是成功了,但是返回一大堆的javascript,还需要再去运算,真麻烦

<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><script type="text/javascript" src="js/common.js"></script>

<input type="hidden" name="_ieStore" id="_ieStore" style="BEHAVIOR:url(#default#userData)" />
<div id="header"></div>
<script language="JavaScript" type="text/javascript">

var main,search_,xhr = null,ready_ = false,isIE =/*@cc_on!@*/! 1;
main = domain();
document.domain = main.replace("login.", "");
var em = $,cElement = $c,eName = $t;
function $(a) {
return document.getElementById(a)
}
function $c(a) {
return document.createElement(a)
}
function $t(a) {
var b = arguments[1] || document;
return b.getElementsByTagName(a)
}
function $cls(a) {
var b = arguments[1] || document,
rs = [],
o = b.getElementsByTagName("*");
for (var i = 0,
t, len = o.length; i < len; i++) {
t = o[i];
if (t.className == a) {
rs.push(t)
}
}
return rs
}
function domain() {
search_ = location.search;
var a = location.host,
_pos = a.indexOf(":");
return (_pos == -1) ? a: a.substring(0, _pos)
}
function g_cookie(a) {
var b = storeUtil.get(a, arguments[1]);
if (b || b == "") {
return b
} else {
return cookieStore.get(a)
}
}
function subs(a, b) {
var c = 0,
_out = "";
for (var d = 0; d < a.length; d++) { (a.charCodeAt(d) > 128) ? c += 2 : c++;
_out += a.charAt(d);
if (c >= b) return _out
}
return _out
}
function s_cookie() {
var a = [],
_para = {};
for (var b = 0,
_len = arguments.length; b < _len; b++) {
a[b] = arguments[b]
}
if (String.prototype.toLowerCase.apply(typeof(a[0])) != "string") {
switch (a[0].store) {
case "ie":
_para.store = ieStore.init();
break;
case "ff":
_para.store = mozillaStore.init();
break;
case "cookie":
default:
_para.store = cookieStore.init()
}
a.splice(0, 1)
}
_para.exps = typeof(a[2]) != "undefined" ? Math.ceil(a[2] / (3600 * 24)) : undefined;
_para.name = a[0];
_para.val = a[1];
_para.path = a[3];
_para.domain = a[4];
_para.secure = a[5];
storeUtil.set(_para);
return false
};
function _body() {
return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement: document.body
}
function initXhr() {
if (window.XMLHttpRequest) {
try {
xhr = new XMLHttpRequest()
} catch(e) {
xhr = false
}
} else if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP")
} catch(e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP")
} catch(e) {
xhr = false
}
}
}
}
String.prototype.trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "")
};
var storeUtil = {
_init: false,
init: function() {
var a = arguments[0],
_store;
if (!a) {
if (isIE) {
_store = ieStore
} else if (window.globalStorage) {
_store = mozillaStore
} else {
_store = cookieStore
}
} else {
switch (a) {
case "ie":
_store = ieStore;
break;
case "ff":
_store = mozillaStore;
break;
case "cookie":
default:
_store = cookieStore
}
}
this.store = _store.init();
this._init = this.store.isInit() ? true: false;
return this.isInit()
},
get: function(a) {
if (this.store == null) {
this.init();
}
var b = arguments[1] || this.store;
return b.get(a)
},
set: function(a) {
var b = a.store || this.store;
b.set(a)
},
del: function(a) {
var b = arguments[1] || this.store;
b.del(a)
},
isInit: function() {
return this._init
}
},
ieStore = {
exps: 180,
_init: false,
init: function() {
if (!this.isInit() && !$("_ieStore")) {
this.store = $c("INPUT"),
this.store.type = "hidden",
this.store.id = "_ieStore",
this.store.addBehavior("#default#userData");
$("header").appendChild(this.store);
this._init = true
} else if ($("_ieStore")) {
this.store = $("_ieStore");
this._init = true
}
return this
},
get: function(a) {
try {
this.store.load(a)
} catch(e) {
return null
}
return this.store.getAttribute("__store__") || null
},
set: function(a) {
var b = a.name,
_val = a.val,
_exps = typeof(a.exps) != "undefined" ? a.exps: this.exps;
var c = new Date();
c.setDate(c.getDate() + _exps);
this.store.load(b);
this.store.expires = c.toUTCString();
this.store.setAttribute("__store__", _val);
this.store.save(b)
},
del: function(a) {
this.set({
name: a
},
false, -1)
},
isInit: function() {
return this._init
}
},
mozillaStore = {
_init: false,
init: function() {
this._domain = main.replace("login.", "");
this._init = true;
return this
},
get: function(a) {
var b = window.globalStorage[this._domain].getItem(a);
return b ? b.value || 0 : null
},
set: function(a) {
window.globalStorage[this._domain].setItem(a.name, a.val)
},
del: function() {
window.globalStorage[this._domain].removeItem(_name)
},
isInit: function() {
return this._init
}
},
cookieStore = {
_init: false,
_exps: 180,
_secure: "",
init: function() {
if (!this.isInit()) {
this._domain = main.replace("login.", "");
this._init = true
};
return this
},
get: function(a) {
var b = document.cookie.split("; "),
a = a + "=";
for (var c = 0,
_len = b.length; c < _len; c++) {
if (b[c].indexOf(a) != "-1") {
try {
return decodeURIComponent(b[c].replace(a, ""))
} catch(e) {
return unescape(b[c].replace(a, ""))
}
}
}
return null
},
set: function(a) {
var b = new Date();
var c = a.name,
_val = a.val,
_exps = typeof(a.exps) != "undefined" ? a.exps: this._exps,
_domain = a.domain || this._domain,
_path = a.path || "/",
_secure = a.secure || this._secure;
b.setDate(b.getDate() + _exps);
var d = c + "=" + escape(_val) + (_exps ? ";expires=" + b.toUTCString() : "") + (_path ? ";path=" + _path: "") + (_domain ? ";domain=" + _domain: "") + (_secure ? ";secure=": "");
document.cookie = d
},
del: function(a) {
if (String.prototype.toLowerCase.apply(typeof(a)) == "string") {
_name = a;
a = {
name: _name,
val: ""
}
}
a.exps = -1;
a.secure = "";
this.set(a)
},
isInit: function() {
return this._init
}
};
linzhen6790 2012-09-06
  • 打赏
  • 举报
回复
半夜了,还没睡,真辛苦。
linzhen6790 2012-09-05
  • 打赏
  • 举报
回复
有没有大哥,看一下错在哪里,分不够在加
linzhen6790 2012-09-04
  • 打赏
  • 举报
回复
原来的密码被人改了,我又重新申请一个

这个是POST数据

这个是POST流

可以看出 post的数据有这几个项

button 7
check_code 11
cmd login 9
forward http://my.2345.com 32
password c2c00ae8a945e4a59ea1d6a2f02af357 41
pwd system123456 16
username system1 16
linzhen6790 2012-09-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
POST 前,先设置一下
IdHttp1.HTTPOptions = [];
[/Quote]

加了,也不行
IdHTTP1.HTTPOptions:=[hoKeepOrigProtocol];
OO_is_just_P 2012-09-03
  • 打赏
  • 举报
回复
cmd=login&forward=http%3A%2F%2Fmy.2345.com&password=54b53072540eeeb8f8e9343e71f28176&username=systemtest&pwd=system&check_code=&button=

全放到Paramstr中,cookie用cookiemanager自动管理
wzca 2012-09-03
  • 打赏
  • 举报
回复
你这数据里有大把的垃圾
我截了一下,你看看比你少得多
------------------------------------------
POST /login.php?forward=http%3A%2F%2Fmy.2345.com HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*
Referer: http://login.2345.com/login.php?forward=http%3A%2F%2Fmy.2345.com
Accept-Language: zh-CN
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: login.2345.com
Content-Length: 135
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: PHPSESSID=lfmad66c9u96qcu3p8gbt0pms6

cmd=login&forward=http%3A%2F%2Fmy.2345.com&password=10d15ccc5a4e6017709544a938b99453&username=system&pwd=systemtest&check_code=&button=
wzca 2012-09-03
  • 打赏
  • 举报
回复
POST 前,先设置一下
IdHttp1.HTTPOptions = [];
linzhen6790 2012-09-03
  • 打赏
  • 举报
回复
那个密码有个JS动作,是MD5加密了

1,594

社区成员

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

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