问题
I am trying to connect my PHP application to ConnectWise API. I never used SoapClient so I am completely lost even after looking over the SoapClient Manual
Here is what the request should look like when it is sent to 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>
How can I use SoapClient to establish the connection and send the required information?
Here is what I have done so far
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>';
But I do not get anything printed beside
REQUEST:
RESPONSE:
来源:https://stackoverflow.com/questions/29548188/how-to-connect-to-non-wsdl-api-via-soapclient-in-php