0

I am trying to send an API call through SoapClient in PHP. Everything works perfectly in my local dev environment, but when I try to do it on the production server, I get the following error:

object(SoapFault)#2 (9) { ["message":protected]=> string(25) "Could not connect to host"

I suspect the problem might come from the proxy we have on the server. I tried to send a Curl request to test if I can reach the API URL, and the following request works:

    $param_curl = array(
        CURLOPT_URL => "https://the.api.com/path",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPPROXYTUNNEL => true,
        CURLOPT_PROXY => "http://my.proxy.com:123"
    );
    curl_setopt_array($curl, $param_curl);
    curl_exec($curl);

But when I try the following call with SoapClient on the server (which works on my local dev environment), I get the "Could not connect to host" error:

    $client = new SoapClient("wsdl.xml", [
        'trace' => 1, 
        'cache_wsdl' => WSDL_CACHE_NONE,
        'proxy_host' => "http://my.proxy.com",
        'proxy_port' => "123"
    ]);
    $result = $client->create($params);

I could send the Soap XML directly in a Curl request, but it kinda ruins the point of the Soap protocol.

Do any of you see something that I might have missed? Thanks a lot!

2
  • Maybe the proxy requires some sort of authentication to access it? We don't know, we've no idea how it's set up. We've no idea if that's the only potential issue either - we don't know your network topology. Maybe speak to the server administrator. Commented Jun 12 at 12:55
  • 1
    @ADyson No authentification is required, as we can see in the Curl configuration since none is passed and this request works fine. The server administrator only gave information about the Host and the Port, which is enough to send a Curl request but not a Soap request. Commented Jun 12 at 14:35

1 Answer 1

0

i think the reason is http protocol,

you could try something like:



$client = new SoapClient("wsdl.xml", [
        'trace' => 1, 
        'cache_wsdl' => WSDL_CACHE_NONE,
        'proxy_host' => "http://my.proxy.com",
        'proxy_port' => "123",
        'stream_context' => stream_context_create(
            array(
                'ssl' => array(
                    'verify_peer'       => false,
                    'verify_peer_name'  => false,
                )
            )
        )
]);

or something like:

$client = new SoapClient("wsdl.xml", [
        'trace' => 1, 
        'cache_wsdl' => WSDL_CACHE_NONE,
        'proxy_host' => "http://my.proxy.com",
        'proxy_port' => "123",
        'stream_context' => stream_context_create(
            array(
                'http' => array(
                    'proxy'       => "tcp://my.proxy.com:123",
                    'request_fulluri'  => true,
                )
            )
        )
]);

and of course check path and content of wsdl.xml

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.