私はRESTサービスを作成しました。これはログインが真であれば文字列 "hej"を返します。 私はJavaでレストクライアントでテストしましたが、うまくいきましたが、javascriptにはかなり新しく、いくつかの助けが必要です。私はこの機能JavascriptとRESTを使用したログイン
function UserAction() {
console.log(User());
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "http://localhost:8080/Footballmanagerrestservice/webresources/login");
xhttp.setRequestHeader("login", User());
xhttp.responseType = 'text';
xhttp.onreadystatechange = function() {
console.log('DONE', xhttp.readyState);
if (xhttp.readyState == 4) {;
// handle response
var response = xhttp.responseText;
console.log(response);
if (response == "hej") {
var url = "http://localhost:8080/FM3/spil2.jsp";
window.location.href = url;
}
}
};
// send the request *after* the callback is defined
xhttp.send();
return false;
}
function User() {
username = document.getElementById("username").toString();
username = document.getElementById("password").toString();
var UserAndPass = "?username=" + username + "&password=" + password;
return UserAndPass;
}
を使用してい
私はあなたに私はそれが働いていない理由を私は、Java、多分あなたが見ることができる持っているクライアントを示しています。
public static void main(String[] args) {
Client client = ClientBuilder.newClient();
String root="http://localhost:8080/Footballmanagerrestservice/webresources/";
String functionPath="login";
String parameters="?username=s153518&password=holger";
Response res = client.target(root+functionPath+parameters)
.request(MediaType.APPLICATION_JSON).get();
String svar = res.readEntity(String.class);
System.out.println(svar);
}
。 User()とは何ですか? – AhmadWabbi
@AhmadWabbiユーザー機能が追加されました:-) –