如何通过PHP中的SoapClient连接到非wsdl API?

时间:2015-04-09 20:19:44

标签: php api soap wsdl soap-client

我正在尝试将我的PHP应用程序连接到ConnectWise API。我从未使用SoapClient,所以即使在查看SoapClient手册

之后我也完全迷失了

以下是发送到ConnectWise时请求应该是什么样子

POST /v4_6_release/apis/2.0/ServiceTicketApi.asmx HTTP/1.1
Host: cw.connectwise.net
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://connectwise.com/GetServiceTicket"

<?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" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetServiceTicket xmlns="http://connectwise.com">
      <credentials>
        <CompanyId>string</CompanyId>
        <IntegratorLoginId>string</IntegratorLoginId>
        <IntegratorPassword>string</IntegratorPassword>
      </credentials>
      <ticketId>int</ticketId>
    </GetServiceTicket>
  </soap:Body>
</soap:Envelope>

如何使用SoapClient建立连接并发送所需信息?

这是我到目前为止所做的事情

error_reporting(E_ALL);
ini_set('display_errors',1);


$client = new SoapClient(
    NULL,
    array(
        'location' => 'http://connectwise.com/GetServiceTicket',
        'uri' => 'http://connectwise.com',
        'trace' => 1,
        'use' => SOAP_LITERAL,
        'style' => SOAP_DOCUMENT,
    )
);


$params = new SoapVar(' <credentials>
                        <CompanyId>mycompany</CompanyId>
                        <IntegratorLoginId>myusername</IntegratorLoginId>
                        <IntegratorPassword>mypassword</IntegratorPassword>
                        </credentials>
                        <ticketId>123</ticketId>', XSD_ANYXML);


    echo "REQUEST:<br>" . htmlentities(str_ireplace('><', ">\n<", $client->__getLastRequest())) . '<br><br>';

echo "RESPONSE:<br>" . htmlentities(str_ireplace('><', ">\n<", $client->__getLastResponse())) . '<br>';

但是我没有在

旁边打印任何东西
REQUEST:


RESPONSE:

0 个答案:

没有答案