Skip to content

Instantly share code, notes, and snippets.

@egulhan
Created March 4, 2014 13:42
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egulhan/9346678 to your computer and use it in GitHub Desktop.
Save egulhan/9346678 to your computer and use it in GitHub Desktop.
Solution of PHP SOAP error: looks like we got no XML document
// Source: http://www.highonphp.com/fixing-soap-exception-no-xml
class SoapClientNG extends \SoapClient{
public function __doRequest($req, $location, $action, $version = SOAP_1_1){
$xml = explode("\r\n", parent::__doRequest($req, $location, $action, $version));
$response = preg_replace( '/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', "", $xml[0] );
return $response;
}
}
// Source: http://stackoverflow.com/questions/14319696/soap-issue-soapfault-exception-client-looks-like-we-got-no-xml-document
function strip_bom( $str ) {
return preg_replace( '/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', "", $str );
}
@braianj
Copy link

braianj commented Dec 18, 2018

how to use it?

@SicorDev
Copy link

My php wants this declaration:

class SoapClientNG extends \SoapClient{

public function __doRequest($request, $location, $action, $version = SOAP_1_1, $one_way = null){

...

}

}

@SicorDev
Copy link

how to use it?

Just put above class code in your php where you want to use SoapClient and then use SoapClentNG instead of SoapClient.

@altwei
Copy link

altwei commented Sep 4, 2020

I have a similar problem, you've been a big help to me

Due to the lack of communication, the interface of the other side did not authorize me, but returned an error message of type string to me, leading to similar errors

@cerw
Copy link

cerw commented Oct 27, 2020

Wors nicely! For me i just had to remove \n at the start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment