API – Fix SoapClient ‘Failed to Load External Entity’ Error

apisoap

I am trying to run a SOAP request from my client's Mangento website.

Its throwing below error

'SOAP-ERROR: Parsing WSDL: Couldn\'t load from \'https://swsim.testing.stamps.com/swsim/swsimv50.asmx?wsdl\' : failed to load external entity "https://swsim.testing.stamps.com/swsim/swsimv50.asmx?wsdl"

Here is my code.

class Stamps extends \Magento\Shipping\Model\Carrier\AbstractCarrierOnline implements \Magento\Shipping\Model\Carrier\CarrierInterface{
    .....
    .....
    public function collectRates(RateRequest $request){
        $wsdl = 'https://swsim.stamps.com/swsim/swsimv50.asmx?wsdl';
        $client = new SoapClient( $wsdl, array( 'trace' =>  true ) );
    }
}

When I try to use exact same code outside of Magento, It working fine.

In Magento, is any way to restrict to access an external entity for some directories.

Best Answer

I have fixed this by manually loading the WSDL from local instead of loading from remote URI.