성공적인 호출을 위해 다음과 같은 입력 메시지가 필요한 서비스가 필요합니다. 나는 컬을 사용하여 서비스를 호출했습니다.XML 페이로드로 Jquery POST 호출
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
데이터에 매개 변수 이름이 누락되어 있지 않은지, 컬 요청은 정확히 어떻게 되었습니까? – felipeclopes
@felipeclopes curl 명령을 사용하기 위해 내 질문을 편집했습니다. – user915745