0

I am using soap client to connect to a wsdl service. the soap client use a custom authentication mode which I am adding them to http by following code

$client=new SoapClient(
        $wsdl,
        array(
            'trace' => 1,
            "stream_context" => stream_context_create(
                array(
                    "http"=>array(
                                    "header"=>  "username: xmluatbank\r\n".
                                                "password: 123456\r\n"
                                )
                    )
            )
);

and the header came as follow.

POST /myweb/Proxy HTTP/1.1
Host: uat.myweb.com:8080
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.4.19
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 1086
username: xmluatbank
password: 123456

so far until here everything was fine, then came new request to need to connect through proxy, so I changed the code to follwing:

$client=new SoapClient(
        $wsdl,
        array(
            'trace' => 1,
            "stream_context" => stream_context_create(
                array(
                    "http"=>array(
                                    "header"=>  "username: xmluatbank\r\n".
                                                "password: 123456\r\n"
                                 )
                    ),
            'proxy_host' => $proxy, 
            'proxy_port' => $proxyport,
            'proxy_login' => $proxyusrname,
            'proxy_password' => $proxypwd,
            )
);

and the header became like this:

POST http://uat.myweb.com:8080/ctos/Proxy HTTP/1.1
Host: uat.myweb.com:8080
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.3.9-ZS5.6.0
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 1086
Proxy-Authorization: Basic YWdyb2JhbmtcanVyaXMudnRjbDpBYmNkMTIx==

as you can see the stream context that I had now is gone,so now I am getting the authentication error with the wsdl server. look like proxy overwrite the the http header. so I tried to add the proxy to http header and not use the soap proxy

$sLogin = base64_encode("$proxyusername:$proxypwd");
$aHTTP['http']['proxy']           = "$proxy:$proxyprot"; 
$aHTTP['http']['method']          = 'POST';
$aHTTP['http']['header']          = "User-Agent: My PHP Script\r\n";
$aHTTP['http']['header']         .= "Proxy-Authorization: Basic $sLogin";
$aHTTP['http']['header']         .= "username: xmluatbank\r\n"."password: 1234567\r\n";
$context = stream_context_create($aHTTP);

and called the soap client like this :

$client=new SoapClient(
        $wsdl,
        array(
            'trace' => 1,
            "stream_context" => $context
            )
);

but this way I am getting soap error and cannot connect to proxy.

 SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://uat.myweb.com:8080/ctos/Proxy?wsdl' : failed to load external entity "http://uat.myweb.com:8080/myweb/Proxy?wsdl"

I am out of idea how to solve this. I tried all that I knew, please help

Mohammad Hossein Amri
  • 1,842
  • 2
  • 23
  • 43
  • What are value of `$proxy`? Can you get wsdl when using curl or similar? Example `curl -X POST --proxy 'http://proxyuser:proxypass@proxyaddr:proxyport' -H 'username: xmluatbank' -H 'password: 123456' 'http://uat.myweb.com:8080/myweb/Proxy?wsdl'` – piotrekkr Sep 25 '14 at 10:43
  • unfortunately bank is using windows server – Mohammad Hossein Amri Sep 25 '14 at 12:21
  • You can use vbscript/powershell like described here http://stackoverflow.com/questions/2710748/run-curl-commands-from-windows-console – piotrekkr Sep 25 '14 at 12:57

1 Answers1

1

I solved the issue by following code, thanks to one of our colleague, look like the issue is with the old version of php on the server

if ( PHP_VERSION <5.4 ) {
     echo "old_version";
     $str_auth_header = "username: xmluatbank\r\n".
                            "password: 123456";
    ini_set('user_agent', 'PHP-SOAP/' . PHP_VERSION . "\r\n" . $str_auth_header);
} 
Mohammad Hossein Amri
  • 1,842
  • 2
  • 23
  • 43