私はalfrescoのカスタム共有ページを作成しています。REST APIのおかげでjavascriptを使って人を作成したいと思います。xmlhttprequestを使ってalfresco RESTApiを作成する
var boby = "{ \"id\": \"bob\",\"firstName\": \"Bob\", \"lastName\": \"LeBricoleur\", \"email\": \"[email protected]\", \"telephone\": \"6666666666\", \"enabled\": true,\"emailNotificationsEnabled\": true, \"password\": \"bob\" }";
console.log(boby);
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("creatingperson").innerHTML = this.responseText;
}
};
xhttp.open("POST", 'http://localhost:8081/share/proxy/alfresco-api/-default-/public/alfresco/versions/1/people', true);
xhttp.setRequestHeader("Content-Type", "application/json"); //curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic YWRtaW46YWRtaW4=' -d '[...]
xhttp.send(boby);
}
[OK]を、これは...私に何も与えないようにさえエラーメッセージ:VARここでこの方法は)ので、私は、データを投稿するのXMLHttpRequestが含まれているこのコードを書きました。私はそれが私の全体のコードのためだと思ったので、デバッグを簡略化するためにサーバーに送る変数bobyを作成しましたが、エラーの原因はまだ分かりません。
私のコードから問題がありますか? APIを使用する私の方法からですか?アルフレツコの共有から?あなたが私に多くの感謝を助けることができれば!
PS:それは助けることができる場合、私は同じURLを使用して動作します(代わりに1を作成する)人をリストアップするためのコードを書いた
[EDIT]
は、私は別の道へのを見つけた
私の要求を作成し、それが動作しますが、私はなぜ知らない...ここにコードです:
var createperson = "{ \"id\": \"" + document.getElementById('login').value + "\",\"firstName\": \"" + document.getElementById('firstName').value + "\", \"lastName\": \"" + document.getElementById('lastName').value + "\", \"email\": \"" + document.getElementById('mail').value + "\", \"telephone\": \"" + document.getElementById('telephone').value + "\", \"enabled\": true,\"emailNotificationsEnabled\": true, \"password\": \"" + document.getElementById('pwd2').value + "\" }";
console.log(createperson);
var url = "http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people";
var method = "POST";
var async = true;
//var postData = "{ \"id\": \"bob\",\"firstName\": \"Bob\", \"lastName\": \"LeBricoleur\", \"email\": \"[email protected]\", \"telephone\": \"6666666666\", \"enabled\": true,\"emailNotificationsEnabled\": true, \"password\": \"bob\" }";
var request = new XMLHttpRequest();
request.onload = function() {
var status = request.status; // HTTP response status, e.g., 201 for "201 OK"
var data = request.responseText; // Returned data, e.g., an HTML document.
console.log("status :");
console.log(status);
console.log("data :");
console.log(data);
}
request.open(method, url, async);
request.setRequestHeader("Content-Type", "application/json");
request.setRequestHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
request.send(createperson);
また
私は人々をリストするために、要求のこのタイプを使用しようとすると、(ちょうどどこでもメソッドを使用するために)それをここでは..動作しません。私は人をリストするために書いたものの一部です:
のでvar url = "http://192.168.1.103:8080/alfresco/api/-default-/public/alfresco/versions/1/people";
var method = "GET";
var async = true;
var request = new XMLHttpRequest();
request.onload = function() {
var status = request.status; // HTTP response status, e.g., 201 for "201 OK"
objet = JSON.parse(request.responseText);
console.log("status :");
console.log(status);
console.log("data :");
console.log(objet);
}
request.open(method, url, async); //, "admin", "admin");
request.setRequestHeader("Content-Type", "application/json");
request.setRequestHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
それが誰かを作成し、なぜそれがリストについては、あなたの答えてくれてありがとうしないために働いて、なぜ誰もが知っていれば!
何らかの種類のRESTクライアントを使用して問題のAPIリクエストを再作成し、そのAPIが機能することを確認してください。そうすれば、その部分が確実に動作することがわかります。 – Lista
使用しているアルフレコのバージョンは? –
@Listaこの部分は働いています。私はPostmanのおかげでそれをやってきました。良い結果が得られました。 – JackA