When trying to use a web service function with SoapClient I get fault code "HTTP" and fault text "Could not connect to host", but when doing the exact same thing except for using a child class to override SoapClient::__doRequest() and have it use curl to send the request, everything works fine. Does anyone have an idea why?
Does not work
$opts = array(
'trace' => 1,
'soap_version' => SOAP_1_2,
'exceptions' => 0,
'login' => DibsWS::APIUSER,
'password' => DibsWS::APIPASS,
'authentication' => SOAP_AUTHENTICATION_BASIC
);
# instantiating works fine
$s = new SoapClient($wsdl, $opts);
# and so do these
$s->__getFunctions();
$s->__getTypes();
# Could not connect to host on this line, "theFunc" is specified in the WSDL doc
$result = $s->theFunc($params);
Works
class CurlSoapClient extends SoapClient
{
function __doRequest($request, $location, $action, $version)
{
$headers = array
(
'Method: POST',
'Connection: Keep-Alive',
'User-Agent: PHP-SOAP-CURL',
'Content-Type: application/soap+xml; charset=utf-8',
);
$ch = curl_init($location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
if ($this->login && $this->password && $this->authentication)
{
curl_setopt($ch, CURLOPT_HTTPAUTH, $this->curlAuth);
curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->password);
}
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$response = curl_exec($ch);
if (curl_errno($ch) !== 0)
{
error_log('CurlSoapClient, curl error ('.curl_errno($ch).'): ' .
curl_error($ch));
return false;
}
$this->__last_request_headers = curl_getinfo($ch, CURLINFO_HEADER_OUT);
$this->__last_request = $request;
return $response;
}
}
$s = new SoapClient($wsdl, $opts);
$result = $s->theFunc($params);