【发布时间】:2012-08-04 07:51:31
【问题描述】:
当用户关注受保护的页面时,我正在使用 Tomcat JDBCRealm 对经过身份验证的用户进行身份验证。到达受保护页面时,身份验证正常工作。现在我想使用 cURL 自动化这个过程。我已经写了下面的代码,但它不起作用:
$domainUrl = "http://mydomain.com/protectedArea?j_username=john&j_password=doe";
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $domainUrl );
//curl_setopt ( $ch, CURLOPT_POST, true );
//curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt ( $ch, CURLOPT_TIMEOUT, 7 );
$output = curl_exec ( $ch );
curl_close ( $ch );
在 tomcat 日志中我们只能看到 http GET :
[07/Aug/2012:11:51:24 +0200] GET http://mydomain.com/protectedArea?j_username=john&j_password=doe HTTP/1.1 200 1618
而我们应该有这样的东西:
[07/Aug/2012:11:57:06 +0200] GET http://mydomain.com/protectedArea?j_username=john&j_password=doe HTTP/1.1 200 1516
[07/Aug/2012:11:57:06 +0200] POST http://mydomain.com/j_security_check HTTP/1.1 302 -
有人知道吗?
感谢您的帮助
问候
【问题讨论】:
-
注意:您不应该将
JDBCRealm用于任何真正重要的事情。相反,请使用DataSourceRealm,它的配置几乎相同,但使用连接池并且不是单线程的。
标签: tomcat curl forms-authentication jdbcrealm