如何在流星HTTP包中转换此卷曲?

时间:2016-10-05 06:59:15

标签: curl meteor soap

curl --data @login.xml https://xxxxx/index.php/api/v2_soap/?wsdl=1.

如何将此curl请求更改为HTTP GET调用?或者是直接在Meteor中调用此卷曲的任何方式。

login.xml包含

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
    <MAGE:login xmlns:MAGE="http://xxxxxx/api/v2_soap/?wsdl=1">
        <MAGE:username>xxxxxxxx</MAGE:username>
        <MAGE:apiKey>xxxxxxxxx</MAGE:apiKey>
    </MAGE:login>
</SOAP-ENV:Body>

我想这样称呼curl:

HTTP.get("https://domain/v1/query?v=20150910&lang=en&query=", {
 headers: {
   Authorization: "Bearer XXXXXXXXXXXXXXXXXXXXXXXX"
  }
});

2 个答案:

答案 0 :(得分:0)

以下是我执行http GET

的一些代码示例
var opts = {npmRequestOptions: {rejectUnauthorized:false, jar: true, contentType: 'text/plain'},
    headers: {Authorization: "Bearer "+p.access_token}
};
var url = p.protocol+'://'
    +p.guardiumIP+':'
    +p.guardiumPort
    +'/restAPI/policy';
console.log("url="+url);
var curlcmd = "curl -k --header \"Authorization:Bearer"+p.access_token+"\"";
curlcmd += " -i -H \"Content-Type: application/json\" -X GET ";
curlcmd += url;
console.log("cmd would be "+curlcmd);
HTTP.get(url,opts,PoliciesCB);

您会在代码中注意到我还构建了一个curl命令并将其记录到控制台,以防我需要手动使用curl来仔细查看返回的数据。

以最小的形式,它看起来像这样:

var opts = {npmRequestOptions: {rejectUnauthorized:false, jar: true, contentType: 'text/plain'},
    headers: {Authorization: "Bearer "+p.access_token}
};
var url = p.protocol+'://'
    +p.guardiumIP+':'
    +p.guardiumPort
    +'/restAPI/policy';
var curlcmd = "curl -k --header \"Authorization:Bearer"+p.access_token+"\"";
HTTP.get(url,opts,PoliciesCB);

答案 1 :(得分:0)

meteor add zardak:soap

在应用程序文件夹的根目录中安装此软件包。然后尝试使用以下代码。

var url = 'http://example.com/wsdl?wsdl';
var args = {name: 'value'};

try {
  var client = Soap.createClient(url);
  var result = client.MyFunction(args);

 console.log(result);
}
catch (err) {
  if(err.error === 'soap-creation') {
    console.log('SOAP Client creation failed');
  }
  else if (err.error === 'soap-method') {
    console.log('SOAP Method call failed');
  }

}

您可以使用这些功能进行任何soap api调用。有关详细信息,请访问:https://atmospherejs.com/zardak/soap