楼主,这个问题简单你访问的http://www.iciba.net/带有弹出式窗口
而HttpUnit默认第一次访问时,得到的是弹出式窗口,
你在访问http://www.iciba.net/他以下就解决了。
不要问我为什么,
因为我也栽过跟头
而HttpUnit默认第一次访问时,得到的是弹出式窗口,
你在访问http://www.iciba.net/他以下就解决了。
不要问我为什么,
因为我也栽过跟头
解决方案 »
- 如何用 java发送很多封邮件
- 文件传输的一点问题
- 从java程序中启动TOMCAT
- TripleDES 两种加密方式的不同
- 在java 里面 怎么让“+00001” 变成“00001”
- 请教JSP页面逻辑代码简化的问题
- 什么问题?
- 请问谁知道java应用程序去掉右上角的关闭菜单。
- 着急,上火,怎么编译一批java文件?
- 哪位高手能给介绍一点关于Java初级方面的书籍,由于是新手只能给22分望大家谅解!!
- 推荐好书~~~~~~~~~~~~~~~~~~~~~~~~~~
- 急!!!在AUTOEXEC.BAT中配置环境变量重起计算机后无法进入WINDOWS系统,高手教我怎样解决,感激不尽!!100分相送!
是不是要访问两次?连着写两遍"GetMethodWebRequest( "http://www.iciba.net/" );"?
我没明白你的意思。
我连着写了两遍错误还是一样的啊。能不能写出来具体的写法,也许我写错了。
我说的意思是:
你默认使用IE访问http://www.iciba.net/这个网站,它会弹出一个窗口,
所以,第一次你访问的http://www.iciba.net/并不是真正的http://www.iciba.net/;至于怎么访问两遍,这和各人程序写法有关了。
我是这么做的(供参考):
WebResponse response = WebConversation.getResponse("http://www.iciba.net/");
response = WebConversation.getResponse("http://www.iciba.net/");
你试试吧,不是很麻烦的。
下面是我刚才照着Leemaasn的办法写的代码
public static void main(String[] args) {
try {
//HttpUnitOptions.setLoggingHttpHeaders(true);
WebConversation WebConversation = new WebConversation();
WebResponse response = WebConversation.getResponse("http://www.iciba.net/");
response = WebConversation.getResponse("http://www.iciba.net/");
if (WebConversation.getExceptionsThrownOnErrorStatus() == true)
{
System.out.println("error:"+response.getURL());
System.out.println("frame1:"+response.getFrameName());
}
System.out.println(response.getText());
}
catch (Exception r) {
System.out.println(r.getMessage());
}
}但是结果依旧,没有改变error:http://www.iciba.net/error.htm?aspxerrorpath=/Default.aspx
frame1:_top
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>金山词霸在线词典 </title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta content="在线词典,web词典,英汉词典,词典,辞典,金山词霸,Dictionary,online" name="Keywords">
<meta content="金山词霸在线词典,是著名词典软件《金山词霸》的在线版本,提供免费在线查找《金山词霸》中的词库。" name="Description">
<LINK href="css/default.css" type="text/css" rel="stylesheet">
<script language="javascript" src="js/validate.js"></script>
</HEAD>
<body>
<iframe scrolling="no" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="27"
src="http://online.kingsoft.net/top/onlineKingsoft.htm"></iframe>
<table cellPadding="0" width="760" align="center">
<tr>
<td vAlign="middle" align="center" height="120"><IMG src="images/logo-c.gif" border="0"></td>
</tr>
<tr>
<td align="center" height="200">
<H1>We’re sorry,</H1>
<P>We’re sorry, but there is error in this Web Page. You may wish to try another
entry or to use the links below, which we hope will help provide you with the
information you need.</P>
<p><a href="./">Home</a></p>
</td>
</tr>
</table>
<table cellPadding="0" width="90%" align="center" ID="Table7">
<tr>
<td height="10" class="footerline"></td>
</tr>
<tr>
<td align="center" height="20" nowrap>
<a id="Footer1_hlIcibaweb" class="footerlink" href="http://www.iciba.com" target="_blank">
金山词霸网站</a><font> :: </font> <a id="Footer1_hlKingsoft" class="footerlink" href="http://www.kingsoft.net" target="_blank">
金山公司网站</a><font> :: </font> <a id="Footer1_hlUserhelp" class="footerlink" href="help" target="_blank">
使用帮助</a><font> :: </font> <a id="Footer1_hlLinkus" class="footerlink" href="mailto:[email protected]">
联系我们</a>
</td>
</tr>
<tr>
<td align="center" height="20" nowrap>
<span id="Footer1_lbCopyright" class="copyright">Copyright © 1996-2004 金山软件
All Rights Reserved</span></td>
</tr>
</table>
</body>
</HTML>
现在程序执行得到的结果是error.htm不是期待的default.aspx
Sat Jan 31 20:34:57 2004 正在连接 www.iciba.net [IP=211.152.52.122:80]
Sat Jan 31 20:34:57 2004 已连接.
Sat Jan 31 20:34:57 2004 GET / HTTP/1.1
Sat Jan 31 20:34:57 2004 Host: www.iciba.net
Sat Jan 31 20:34:57 2004 Accept: */*
Sat Jan 31 20:34:57 2004 Referer: http://www.iciba.net
Sat Jan 31 20:34:57 2004 User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
Sat Jan 31 20:34:57 2004 Pragma: no-cache
Sat Jan 31 20:34:57 2004 Cache-Control: no-cache
Sat Jan 31 20:34:57 2004 Connection: close
Sat Jan 31 20:34:58 2004 HTTP/1.1 302 Found
Sat Jan 31 20:34:58 2004 Server: Microsoft-IIS/5.0
Sat Jan 31 20:34:58 2004 Date: Sat, 31 Jan 2004 12:25:41 GMT
Sat Jan 31 20:34:58 2004 X-Powered-By: ASP.NET
Sat Jan 31 20:34:58 2004 Connection: close
Sat Jan 31 20:34:58 2004 X-AspNet-Version: 1.1.4322
Sat Jan 31 20:34:58 2004 Location: /error.htm?aspxerrorpath=/Default.aspx
Sat Jan 31 20:34:58 2004 Cache-Control: private
Sat Jan 31 20:34:58 2004 Content-Type: text/html; charset=utf-8
Sat Jan 31 20:34:58 2004 Content-Length: 155
Sat Jan 31 20:34:58 2004 重定向到 /error.htm?aspxerrorpath=/Default.aspx
Sat Jan 31 20:34:58 2004 正在连接 www.iciba.net [IP=211.152.52.122:80]
Sat Jan 31 20:35:00 2004 User Cancel At 0.
七、HTTP应答状态
作 者 : 仙人掌工作室
7.1 状态代码概述 302 Found 类似于301,但新的URL应该被视为临时性的替代,而不是永久性的。注意,在HTTP1.0中对应的状态信息是“Moved Temporatily”,而HttpServletResponse中相应的常量是SC_MOVED_TEMPORARILY,而不是SC_FOUND。
出现该状态代码时,浏览器能够自动访问新的URL,因此它是一个很有用的状态代码。为此,Servlet提供了一个专用的方法,即sendRedirect。使用response.sendRedirect(url)比使用response.setStatus(response.SC_MOVED_TEMPORARILY)和response.setHeader("Location",url)更好。这是因为:
首先,代码更加简洁。
第二,使用sendRedirect,Servlet会自动构造一个包含新链接的页面(用于那些不能自动重定向的老式浏览器)。
最后,sendRedirect能够处理相对URL,自动把它们转换成绝对URL。
注意这个状态代码有时候可以和301替换使用。例如,如果浏览器错误地请求http://host/~user(缺少了后面的斜杠),有的服务器返回301,有的则返回302。
GET / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
Host: www.iciba.net
Connection: Keep-Alive
Cookie: UserName=leonpard
======================IE接收=============
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Sat, 31 Jan 2004 12:37:32 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Set-Cookie: ASP.NET_SessionId=xnkkssbvzyk1ppm3li4fjo55; path=/
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 5568Cookie: UserName=leonpard**********************************我的java程序发送====
GET / HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
Cookie: UserName=leonpard
Accept-Encoding: gzip
Cache-Control: no-cache
Pragma: no-cache
Host: www.iciba.net
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive=========================我的java程序接收========
HTTP/1.1 302 Found
Server: Microsoft-IIS/5.0
Date: Sat, 31 Jan 2004 13:17:59 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Location: /error.htm?aspxerrorpath=/Default.aspx
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 155
我截获了两个程序的http包文,到底导致200和302的区别在哪里呢?
在某个条件不满足的时候,就重定向了。
至于是到底是检测了什么条件,我猜不出来:(
我也不懂:( 只有期待其他人来指点啦:
下面是Mozilla 1.6的包:GET / HTTP/1.1
Host: www.iciba.net
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040113
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-aliveHTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Sat, 31 Jan 2004 14:20:19 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Set-Cookie: ASP.NET_SessionId=pu5qzwvilqid1ajxmn4sfiyt; path=/
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 5527
IE6的包:GET / HTTP/1.1
Accept: */*
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; MyIE2; .NET CLR 1.1.4322)
Host: www.iciba.net
Connection: Keep-Alive
Cookie: ASP.NET_SessionId=avbilj55r2d0x055xjyxjw55HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Sat, 31 Jan 2004 14:13:26 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 5568
你先看看楼上各位的。
我现在重新看看。
发现在HttpUnit里,通过多次访问:
http://www.iciba.net/
确实无法得到Ie里浏览器的页面;估计词霸公司确实如: pigo() 说的,做了某些限制或过滤或重定向的手法;通过观察Ie状态栏和FlashGet的相关信息:
猜测:
http://online.kingsoft.net/top/onlineKingsoft.htm
是它真正的页面,
不过,它好像采用了框架,
http://online.kingsoft.net/top/onlineKingsoft.htm
得到的只是它的头部,我想,如果你确实想得到Ie里的页面,
你或许需要模仿Ie的功能,逐步与iciba对话,得到完整的页面;
通过简单的HttpUnit功能,似乎无法达到你的目标;你或者可以考虑扩展HttpUnit;这个问题比较有趣,回头再研究研究;
目前应该是只过滤掉了httpUnit和Flashget这样的http通讯程序。
http://tech.ccidnet.com/pub/article/c295_a10105_p1.html