1
回答
HttpClient访问juniper管理的VPN中的Web Application
华为云实践训练营,热门技术免费实践!>>>   

Web App位于公司内网中,公网用户可通过VPN访问Web应用(https),Juniper管理着VPN,公网用户需进行两次用户验证,Juniper的验证和web应用的用户验证。

现为了测试公网访问的性能,在客户端用HttpClient模拟浏览器,代码如下:

HttpClient client = new HttpClient();

client.getParams().makeStrict(); //此句必需

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 );

//服务器上可使用HttpServletResponse.addHeader( key, value )向客户端返回附加信息,其中key必须是

系统内定的key(如location),如使用自定义的key,客户端可能无法得到值。

String locationHeader = postMethod.getResponseHeader( "location" );
System.out.println( locationHeader )

举报
红薯
发帖于9年前 1回/907阅
顶部