呼び出しを成功させるには、次の入力メッセージを期待するサービスが必要です。curlを使用してサービスを呼び出しました。
POST /airavata-registry-rest-services/registry/api/hostdescriptor/save HTTP/1.1
User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
Host: 127.0.0.1
Accept: text/plain
Content-Type: text/xml
Content-Length: 191
<type:hostDescription xmlns:type="http://schemas.airavata.apache.org/gfac/type">
<type:hostName>LocalHost11</type:hostName>
<type:hostAddress>127.0.0.1</type:hostAddress></type:hostDescription>
私が使用したcurlコマンドは次のとおりです。
curl -H "Accept: text/plain" -X POST -H "Content-Type: text/xml" -d '<type:hostDescription xmlns:type="http://schemas.airavata.apache.org/gfac/type"><type:hostName>LocalHost11</type:hostName><type:hostAddress>127.0.0.1</type:hostAddress></type:hostDescription>' http://localhost:6060/airavata-registry-rest-services/registry/api/hostdescriptor/save
Jqueryを介して同じサービスを呼び出そうとしていますが、同じリクエストを生成できません。私が書いたコードは次のとおりです。
var hostName = $("#hostName1").val();
var hostAddress = $("#hostAddress1").val();
var xml = $('<type:hostDescription xmlns:type="http://schemas.airavata.apache.org/gfac/type"><type:hostName>' + hostName + '</type:hostName><type:hostAddress>' + hostAddress + '</type:hostAddress></type:hostDescription>');
var xmlData= $(xml);
var xmlString;
if (window.ActiveXObject){
xmlString = xmlData.xml;
} else {
var oSerializer = new XMLSerializer();
xmlString = oSerializer.serializeToString(xmlData[0]);
}
console.log(xmlString);
$.ajax({
headers: {
Accept : "text/plain; charset=utf-8",
"Content-Type": "text/plain; charset=utf-8",
"Accept-Encoding" : ""
},
type: "POST",
url: "http://localhost:6060/airavata-registry-rest-services/registry/api/hostdescriptor/save",
data: xmlString,
dataType: "xml",
cache: false,
error: function() { alert("No data found."); },
success: function(xml) {
alert("it works");
}
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
上記のメソッドが生成するリクエストは次のようになります。メッセージ本文もありません。上記のサービスを呼び出すようにjquery関数を変更する方法を提案できますか?
OPTIONS /airavata-registry-rest-services/registry/api/hostdescriptor/save HTTP/1.1
Host: 127.0.0.1
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://localhost:7080
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Ubuntu/12.04 Chromium/20.0.1132.47 Chrome/20.0.1132.47 Safari/536.11
Access-Control-Request-Headers: origin, contenttype, content-type, accept
Accept: */*
Referer: http://localhost:7080/client-api-demo/x_host_descriptor_save.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3