来自bash shell的XMLA / SOAP命令

时间:2015-10-16 08:06:36

标签: bash soap xmla iccube

我需要使用bash shell从icCube调用管理API。发送SOAP命令的最简单方法是:

    <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
     <soap:Body>
       <Execute xmlns="urn:schemas-microsoft-com:xml-analysis">
         <Command>
           <Statement xsi:type="xsd:string">'"$command"'</Statement>
         </Command>
       </Execute>
     </soap:Body>
    </soap:Envelope>

最重要的是,如何处理基本身份验证(user / pwd)?

1 个答案:

答案 0 :(得分:1)

文档中提供的Perl示例:http://www.iccube.com/support/documentation/user_guide/using/cube_management.php(在文档末尾)。

使用&#39; - 用户&#39;处理卷曲基本身份验证参数

Bash示例:

  #!/bin/bash

  URL="http://localhost:8282/icCube/xmla"
  COMMAND="LIST_SCHEMA"

  echo ${COMMAND}

  curl --header "Content-Type: text/xml;charset=UTF-8" \
  --header "SOAPAction:urn:schemas-microsoft-com:xml-analysis#Execute" \
  --user admin:admin --data @- ${URL} <<EOF
  <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
    <Execute xmlns="urn:schemas-microsoft-com:xml-analysis">
      <Command>
          <Statement xsi:type="xsd:string">${COMMAND}</Statement>
      </Command>
    </Execute>
      </soap:Body>
  </soap:Envelope>
  EOF

注意:确保在结束EOF后没有任何空格,否则API将返回SOAP语法错误。