怎么用url类实现访问一个页面里面的一个url

cutemouse 2008-03-18 10:43:41
现在有一个url1 里面有一个url2,请问如何在保持连接的情况下用java通过url1访问rul2,
rul1:http://218.200.160.29/wm/store/renew.do?cid=cid%3A600655001992
url2:href="http://218.200.160.29/wm/store/reright.do?cid=600655001992&pid=1&tokenkey=200803111048330005346&mid=13412345678&did=nokian73&ch=000000&bid=000000

现在用浏览器访问url1,点击(或者右键打开)url2是成功访问;
但是:
用浏览器访问url1,查看代码获取url2,然后开一个新的浏览器访问url2,是失败的.
用java开两个httpUrlConnection先后打开url2和url2,也是失败的.
经过抓包,没有发现任何sessionid和cookie的信息.
请教有没有人知道怎么模拟呢?
谢谢。
...全文
226 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
MonEdu 2008-05-02
哪用这么麻烦啊,你获取了也没有用 真正下载的时候会在下到99%的时候提示下载失败的,
  • 打赏
  • 举报
回复
cutemouse 2008-03-22
一、成功访问url1和url2的情况
用opera/9.10 连接cmwap
访问url1的头

[2008-3-14 8:08:11:640]
GET http://218.200.160.29/wm/store/renew.do?cid=cid%3A600602037662&dl=1&ch=000000&cch=00000000000&bid=080313 HTTP/1.0
User-Agent: Opera/9.10 (Windows NT 5.1; U; en)
Host: 218.200.160.29
Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1
Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
Proxy-Connection: close

访问url1的返回的http头

[2008-3-14 8:08:12:593]
HTTP/1.0 200 OK [ZTEOSE]
Server: ZTEOSE
X-Cache: MISS from 12530.com
Via: 1.0 12530.com:80 (squid/2.6.STABLE16)
Connection: close
Content-Length: 1589
Content-Type: text/vnd.wap.wml;charset=UTF-8

(成功的url1页面信息)
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

访问url2的http头


[2008-3-14 8:10:05:281]
GET http://218.200.160.29/wm/store/reright.do?cid=600602037662&pid=4&tokenkey=200803140808300000658&mid=13412345678&did=nokian73&ch=000000&bid=080313 HTTP/1.0
User-Agent: Opera/9.10 (Windows NT 5.1; U; en)
Host: 218.200.160.29
Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1
Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
Proxy-Connection: close

访问url2的返回的http头

[2008-3-14 8:10:06:921]
HTTP/1.0 200 OK [ZTEOSE]
Server: ZTEOSE
X-Cache: MISS from 12530.com
Via: 1.0 12530.com:80 (squid/2.6.STABLE16)
Connection: close
Content-Length: 1276
Content-Type: text/vnd.wap.wml;charset=UTF-8

(url2成功的页面信息)
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

用WinWAP/3.2访问 连接cmwap

[2008-3-14 17:22:46:421]
GET http://218.200.160.29/wm/store/renew.do?cid=cid%3A228156 HTTP/1.0
User-Agent: WinWAP/3.2 (3.2.1.25; Win32)
Accept: application/vnd.wap.wmlc, text/vnd.wap.wml, image/vnd.wap.wbmp, image/gif, image/jpeg, application/vnd.wap.wmlscriptc, text/vnd.wap.wmlscript
Host: 218.200.160.29
Cache-Control: no-cache
Cache-Control: no-cache


[2008-3-14 17:22:47:281]
HTTP/1.0 200 OK [ZTEOSE]
Server: ZTEOSE
X-Cache: MISS from 12530.com
Via: 1.0 12530.com:80 (squid/2.6.STABLE16)
Content-Length: 1580
Content-Type: text/vnd.wap.wml;charset=UTF-8

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
。。。成功的页面信息

[2008-3-14 17:22:56:078]
GET http://218.200.160.29/wm/store/reright.do?cid=228156&pid=4&tokenkey=200803141723060000579&mid=13412345678&did=nokian73&ch=000000&bid=000000 HTTP/1.0
User-Agent: WinWAP/3.2 (3.2.1.25; Win32)
Accept: application/vnd.wap.wmlc, text/vnd.wap.wml, image/vnd.wap.wbmp, image/gif, image/jpeg, application/vnd.wap.wmlscriptc, text/vnd.wap.wmlscript
Host: 218.200.160.29
Cache-Control: no-cache
Cache-Control: no-cache
Referer: http://218.200.160.29/wm/store/renew.do?cid=cid%3A228156


[2008-3-14 17:22:57:718]
HTTP/1.0 200 OK [ZTEOSE]
Server: ZTEOSE
X-Cache: MISS from 12530.com
Via: 1.0 12530.com:80 (squid/2.6.STABLE16)
Content-Length: 1279
Content-Type: text/vnd.wap.wml;charset=UTF-8

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
。。。同样是返回成功的页面信息


二、我用java的urlhttpconnetion 访问
访问rul1,的发送数据头。
[2008-3-14 17:11:39:390]
GET http://218.200.160.29/wm/store/renew.do?cid=cid%3A228158 HTTP/1.1
User-Agent: Opera/9.11 (Windows NT 5.1; U; en)
Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
Proxy-Connection: close
Host: 218.200.160.29


[2008-3-14 17:11:41:875]
HTTP/1.0 200 OK [ZTEOSE]
Server: ZTEOSE
X-Cache: MISS from 12530.com
Via: 1.0 12530.com:80 (squid/2.6.STABLE16)
Connection: close
Content-Length: 1589
Content-Type: text/vnd.wap.wml;charset=UTF-8

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
。。。访问url1返回的页面和用winwap的一样,是一个同样的wap页面;


第二步新建立一个httpurlconnetion,通过url1返回的页面得到url2,连接url2
[2008-3-14 17:11:42:453]
GET http://218.200.160.29/wm/store/reright.do?cid=228158&pid=4&tokenkey=200803141711580009077&mid=13412345678&did=nokian73&ch=000000&bid=000000 HTTP/1.1
User-Agent: Opera/9.11 (Windows NT 5.1; U; en)
Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0
Proxy-Connection: close
Referer: http://218.200.160.29/wm/store/renew.do?cid=cid%3A228158
Host: 218.200.160.29


[2008-3-14 17:11:44:843]
HTTP/1.0 200 OK [ZTEOSE]
Server: ZTEOSE
X-Cache: MISS from 12530.com
Via: 1.0 12530.com:80 (squid/2.6.STABLE16)
Connection: close
Content-Length: 1196
Content-Type: text/vnd.wap.wml;charset=UTF-8

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
访问rul2返回的是一个失败提示的页面,这个情况和在winwap里面访问时候,从代码里面copy出url2直接在一个新winwap的地址栏目里输入一样是失败提示的wap页面,必须要直接在wap页面上点击才成功。
我又用socket直接连代理服务器,保持一个和代理服务器的tcp连接,两次模拟发送http数据,同样的情况,和用httpurlconnetion两个连接一样,不成功。
  • 打赏
  • 举报
回复
haoxiongok 2008-03-19
[Quote=引用 1 楼 Squall1009 的回复:]
应该是
HTTP头中HTTP_REFERER字段的值的问题。通过这个url2可以知道你是从url1过来的(可以用来防止盗链)。
你可以尝试使用url2的setRequestProperty("HTTP_REFERER","http://218.200.160.29");来模拟一下。
如果还是不行-_-!,建议你通过一个代理服务器。
看下通过http://218.200.160.29/wm/store/renew.do?cid=cid%3A600655001992
点击url2的时候发送给服务器的http的报头是什么样子的。
[/Quote]
  • 打赏
  • 举报
回复
Squall1009 2008-03-19
GET /hahaha HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*
Referer: http://127.0.0.1:8080/1.html
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 1.7; .NET CLR 2.0.50727)
Host: 保密:8234
Connection: Keep-Alive


差得应该就是红色的部分标注的信息
  • 打赏
  • 举报
回复
Squall1009 2008-03-18
应该是
HTTP头中HTTP_REFERER字段的值的问题。通过这个url2可以知道你是从url1过来的(可以用来防止盗链)。
你可以尝试使用url2的setRequestProperty("HTTP_REFERER","http://218.200.160.29");来模拟一下。
如果还是不行-_-!,建议你通过一个代理服务器。
看下通过http://218.200.160.29/wm/store/renew.do?cid=cid%3A600655001992
点击url2的时候发送给服务器的http的报头是什么样子的。
  • 打赏
  • 举报
回复
相关推荐
发帖
Java SE
加入

6.2w+

社区成员

Java 2 Standard Edition
社区管理员
  • Java SE
申请成为版主
帖子事件
创建了帖子
2008-03-18 10:43
社区公告
暂无公告