@
hxsf 这是我在 chrome 里看到的 portal.js 的一部分:
$("form#loginForm").submit(function() { // loginForm is submitted
var username = $('#username').val(); // get username
var password = $('#password').val(); // get password
if (username && password) { // values are not empty
$.ajax({
type: "POST",
url: "login.php", // URL of the PHP script
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
// send username and password as parameters to the Perl script
data: {username:username, password:password},
// script call was *not* successful
error: function(XMLHttpRequest, textStatus, errorThrown) {
/*$('div#loginResult').text("responseText: " + XMLHttpRequest.responseText
+ ", textStatus: " + textStatus
+ ", errorThrown: " + errorThrown);*/
$('div#loginResult').text("Internal Error, Login Failed!");
$('div#loginResult').addClass("error");
}
,succes:
})}
是不是这样的代码就可以实现所需的功能?
curl -H "Content-Type: application/json" -X POST -d '{"username":"123","password":"abc"}' login.php
如果认证页面是 https 的,这样明文发送密码也可以吧...