高分求解HttpClient访问Juniper管理的web应用的登录问题
web应用位于公司内网中,公网用户可通过VPN访问应用(https),Juniper管理着VPN,WEB应用已被
Juniper改写了url,公网用户需进行两次用户验证,Juniper的验证和web应用的用户验证.
现为了测试公网访问的性能,在客户端用HttpClient模拟浏览器,两次验证都已通过,HttpClient
的PostMethod.getResponseBodyAsString()已返回Web应用的首页,但是接着访问Web应用的功能
时,HttpClient又跳出到Juniper的用户验证页面. 代码如下:
HttpClient client = new HttpClient();
Protocol easyhttps = new Protocol( "https", new EasySSLProtocolSocketFactory(), 443 );
Protocol.registerProtocol( "https", easyhttps );
PostMethod postMethod = new PostMethod( "https://公网ip/dana-na/auth/url_default/login.cgi" ); //这里是juniper用户验证
NameValuePair pairA = new NameValuePair( "username", URIUtil
.encodeQuery( "user" ) );
NameValuePair pairB = new NameValuePair( "password", URIUtil
.encodeQuery( "password" ) );
NameValuePair pairC = new NameValuePair( "realm", URIUtil
.encodeQuery( "Users" ) );
NameValuePair pairD = new NameValuePair( "tz_offset", URIUtil
.encodeQuery( "" ) );
NameValuePair[] pair = new NameValuePair[] { pairA, pairB, pairC, pairD };
postMethod.setRequestBody( pair );
client.executeMethod( postMethod );
postMethod.releaseConnection();
postMethod = new PostMethod( "https://公网ip/Security,DanaInfo=内网ip,Port=内网端口+" );
//这里是web应用用户验证
pairA = new NameValuePair( "userName", URIUtil
.encodeQuery( "webuser" ) );
pairB = new NameValuePair( "password", URIUtil
.encodeQuery( "webpassword" ) );
pair = new NameValuePair[] { pairA, pairB };
postMethod.setRequestBody( pair );
client.executeMethod( postMethod );
System.out.println( postMethod.getResponseBodyAsString().) //此处返回web应用首页内容
//这里访问web应用的功能
postMethod = new PostMethod( URIUtil.encodeQuery( "https://公网ip/calendar/todolist.do,DanaInfo=内网ip,Port=内网端口+" ) );
client.executeMethod( postMethod );
String locationHeader = postMethod.getResponseHeader( "location" );
System.out.println( locationHeader ) //发现返回到juniper用户登录页面
直接在IE中按上面步骤粘贴url来访问,则一切正常
请高手们看看问题出在哪里,谢谢