Bug #49853 [Com]: Soap Client stream context header option ignored

From: Date: Thu, 22 Sep 2011 10:14:14 +0000
Subject: Bug #49853 [Com]: Soap Client stream context header option ignored
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-163784@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=49853&edit=1

 ID:                 49853
 Comment by:         dave dot wilcock at gmail dot com
 Reported by:        rumana024 at yahoo dot com
 Summary:            Soap Client stream context header option ignored
 Status:             Open
 Type:               Bug
 Package:            SOAP related
 Operating System:   Windows XP
 PHP Version:        5.2SVN-2009-10-12 (SVN)
 Block user comment: N
 Private report:     N

 New Comment:

[VERSION]
PHP 5.3.2 (cli) (built: Apr 27 2010 20:28:18)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by 
eAccelerator

[CODE]
$str_auth_header = "Authorization: Bearer ". $str_token;
      
$arr_context = array('http' =>array('header' => $str_auth_header));

$obj_context = stream_context_create($arr_context);

$arr_options = array (
   'soap_version' => 'SOAP_1_2',
   'encoding' => 'UTF-8',
   'exceptions' => true,
   'trace' => true,
   'cache_wsdl' => 'WSDL_CACHE_NONE',
   'stream_context' => $obj_context
);

$this->obj_connection = new SoapClient(self::STR_BASE_URL, $arr_options);

[EXPECTED]
Authorization header in HTTP request

[GOT]
No Authorization header in HTTP request

[WORKAROUND/CODE]
ini_set('user_agent', 'PHP-SOAP/' . PHP_VERSION . "\r\n" .
$str_auth_header);

[COMMENT]
No idea why appending the user agent string with the headers would work, but it 
seemingly does. Bizarre.


Previous Comments:
------------------------------------------------------------------------
[2011-05-09 17:09:04] vidalis dot aris at gmail dot com

Using php5.3.6 i couldn't pass extra HTTP headers to the SOAP request.
stream_context_create appears to get ignored

[VERSION]
PHP 5.3.6 with Suhosin-Patch (cli) (built: Apr 18 2011 11:14:25)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

[CODE]
$context = stream_context_create(array('http' => array('header' =>
"token: 
85E91AAC-7A4A-11E0-B46B-78E7D1E19752\r\n")));

        $soapparams = array(                    
                                                'stream_context' => $context,
                                                'trace' => 1,
                                                'exceptions' => 1,
                                                'soap_version' => SOAP_1_2,
                                                'encoding' => 'UTF-8',
                                                'features' => 
SOAP_SINGLE_ELEMENT_ARRAYS
                                );
$client = new SoapClient($wsdl,$soapparams);

[REQUEST HEADERS]
POST /SocialMetadataService HTTP/1.1
Host: test.host.com:9080
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.3.6
Content-Type: application/soap+xml; charset=utf-8; action="urn:getObjectID"
Content-Length: 331

------------------------------------------------------------------------
[2009-10-15 18:48:44] rumana024 at yahoo dot com

I have solved my issue... Yahoooooooooo...
I switched to php5.3. And I now the http headers are passing through.

------------------------------------------------------------------------
[2009-10-14 23:31:01] rumana024 at yahoo dot com

I see a conversation at http://aspn.activestate.com/ASPN/Mail/Message/php-dev/3710449
about Transfer-Encoding: chunked and its affect on stream_context parameters. Is this the problem?

------------------------------------------------------------------------
[2009-10-14 19:37:32] rumana024 at yahoo dot com

Is this a PHP bug? If not,can you please post some sample !working! code on creating a SOAP Client
with the stream_context option and http header(in this case https). Those headers can be seen as the
part of the http request headers. I have pretty much tried different suggestions that I read on
diffrent threads on www and php.net to make a successful soap call.    

Regards
RI

------------------------------------------------------------------------
[2009-10-13 18:03:07] rumana024 at yahoo dot com

$headers = array('X-USERID: user_1253314668.com\r\n', 
                'Content-type: application/x-www-form-urlencoded\r\n',
                'X-PASSWORD: 1253314679\r\n',
                'X-SIGNATURE: AtQaNHC.hbpghF5uGCRO99PVYV7ki3.SAb3vQzBlBAxEyi0b\r\n',
                'X-VERSION: 1.2.0\r\n',
	        'X-PROTOCOL: SOAP11\r\n',
                'X-SOURCE: PHP_SOAP_SAMPLE_V1\r\n');	

$context = stream_context_create(array('http' => array('header' =>
$headers)));

$soapClient = new SoapClient(null,array('location' => "https://svcs.sandbox.com/Method1/", 
                                        'uri' => "http://x.x.com/types/test", 
                                        'soap_version' => SOAP_1_1,'trace'
=> 1, 'stream_context' => $context)); 



//Constructing the Payload
$param = "the payload"
$result = $soapClient->Method1($params);


I have changed the wrapper from https to http. Also made the header an array. Still the same error.
I do not see the http header with other http headers when print the
$soapClient->_getLastRequestHeaders(). Please advice how to resolve the issue.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=49853


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=49853&edit=1


Thread (14 messages)

« previous php.bugs (#163784) next »