Aug 11, 2011

PHP - Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in …

I receive this nasty error yesterday and it took me some time to figure out the problem. This line passes without any problems

$client = new SoapClient($url);

and this

var_dump($client->__getFunctions());

shows the function prototypes correctly. So it connects and gets the data but when I try to call a function I receive this error

Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in MyFile.php:23 Stack trace: #0 [internal function]: SoapClient->__doRequest('__call('myFunction', Array) #2 …

I made fast research and found that people receive this error when their php installation isn’t right or because they are trying to use it with https without the openSSL extension. So you can receive this problem with various situations. Anyway my code was right so I took a look at the service description that I received from the server and there was the problem. The server wasn’t configured right

<service name='myService'>
 ...
  <soap:address location='http://some_other_url'/>
 ..
</service>

It was configured to send invalid url and the function calls were using that invalid url. So there are two solutions - one correct and one that is almost correct but it works for testing purposes when you wait for people to fix their server. So the first is to configure the server correctly. The other is to give __doReguest the correct location.
I hope this will help somebody because founding the problem was very frustrating for me.

3 comments:

Anonymous said...

Well, in my case this was true.

iBoedel said...

Hi, can you type a sample-code for a correct __doRequest since we can't alter the server because its ohter companie.

the php.net website didn't work out for me (yet)

thx

eaziweb said...

i was facing the same issue
check the solution here
http://eaziweb.blogspot.com/2012/05/php-soap-client-uncaught-soapfault.html

Popular Posts