Search code examples
phpsoapsoap-client

Uncaught SoapFault exception: [HTTP] Unsupported Media Type when i use SoapClient


So i'm trying to get an appropriate response from the wsdl API but i keep getting the same error

"Unsupported Media type"

 $opts = array(
'http' => array(
        'user_agent' => 'PHPSoapClient',
        'Content-Type' => 'application/soap+xml'
    )
  );
 $ctx = stream_context_create($ctx_opts);

     $options = array( 
            'soap_version'=>'SOAP_1_1', 
            'stream_context' => $ctx,
            'keep_alive' => true
          ); 
    $params = array(
            'UserId'=>'xxxx',
            'Password'=>'xxxx',
            'PassKey'=>'xxxxx'
           );
      $client = new SoapClient('http://bsestarmfdemo.bseindia.com/MFOrderEntry/MFOrder.svc?wsdl',$options);
      $response = $client->getPassword($params);

I've tried changing the SOAP version to both SOAP 1.1 and SOAP 1.2 and even use text/xml as my Content-type but that does seem to work either throwing the same error. Any suggestions?


Solution

  • Found the error. it was because i set SOAP 1_2 in quotes when actually it's a predefined constant.