Eu quero fazer no meu jquery o mesmo post que esse método abaixo faz:
private static String getTicketGrantingTicket(final String server,
final String username, final String password) {
final HttpClient client = new HttpClient();
final PostMethod post = new PostMethod(server);
post.setRequestBody(new NameValuePair[] {
new NameValuePair("username", username),
new NameValuePair("password", password) });
try {
client.executeMethod(post);
final String response = post.getResponseBodyAsString();
// System.out.println(post.getResponseHeader("location"));
switch (post.getStatusCode()) {
case 201: {
final Matcher matcher = Pattern.compile(
".*action=\".*/(.*?)\".*").matcher(response);
if (matcher.matches())
return matcher.group(1);
LOG.warning("Successful ticket granting request, but no ticket found!");
LOG.info("Response (1k): "
+ response.substring(0,
Math.min(1024, response.length())));
break;
}
default:
LOG.warning("Invalid response code (" + post.getStatusCode()
+ ") from CAS server!");
LOG.info("Response (1k): "
+ response.substring(0,
Math.min(1024, response.length())));
break;
}
}
catch (final IOException e) {
LOG.warning(e.getMessage());
}
finally {
post.releaseConnection();
}
return null;
}
A variável server recebe o a url de um servidor CAS (que é externo), devidamente configurado (isso está OK, pois o código Java funciona)
Porém agora quero fazer a mesma requisição a esse servidor CAS (externo) no .js
Tentei o seguinte:
$(document).ready(function($) {
$("#btn_login").click( logarUsuario );
});
function logarAluno() {
var username = $("#username").val();
var password = $("#password").val();
$.post('url do servidor cas', {username: username, password: password}, function(data) {
alert("oi");
});
}
Não obtenho o alert("oi");
Então... como deveria esse .js ?
Valeu :) :D