1

我有一个休息服务,我正在尝试通过 jquery 客户端调用它。当我通过 CURL 发送如下响应时,后端休息服务工作正常。

curl -H "Accept: text/plain" -X POST -d 'host=<type:hostDescription xmlns:type="http://schemas.airavata.apache.org/gfac/type"><type:hostName>testHost5</type:hostName><type:hostAddress>aaaa</type:hostAddress></type:hostDescription>' http://localhost:6060/airavata-registry-rest-services/registry/api/hostdescriptor/save

此请求如下所示。

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-Length: 189
Content-Type: application/x-www-form-urlencoded

host=<type:hostDescription xmlns:type="http://schemas.airavata.apache.org/gfac/type">
   <type:hostName>testHost5</type:hostName>
   <type:hostAddress>aaaa</type:hostAddress></type:hostDescription>

但问题是我的 jquery 客户端发送的请求如下所示。

POST /airavata-registry-rest-services/registry/api/hostdescriptor/save HTTP/1.1
Host: 127.0.0.1
Connection: keep-alive
Content-Length: 276
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
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
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

host=%3Ctype%3Ahostdescription+xmlns%3Atype%3D%22http%3A%2F%2Fschemas.airavata.apache.org%2Fgfac%2Ftype%22%3E%3Ctype%3Ahostname%3Eutav%3C%2Ftype%3Ahostname%3E%3Ctype%3Ahostaddress%3Egatekeeper2.ranger.tacc.teragrid.org%3C%2Ftype%3Ahostaddress%3E%3C%2Ftype%3Ahostdescription%3E

我的 jquery 代码片段如下所示;

$('[name="btn2"]').click(function(){
            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);

            $.post("http://localhost:6060/airavata-registry-rest-services/registry/api/hostdescriptor/save",
                    { host: xmlString} ,function(data,status){
                        alert("Data: " + data + "\nStatus: " + status);
                        alert("button2 post sent !");
                    });
        });

我应该如何更改我的客户以正确调用此服务。

4

0 回答 0