0

I have created a custom shipping method in Magento but my question how i can call a request from external gateway and read XML data in Magento shipping method .

0

You need to use below code in your shipping module.

Use curl to get data from external url

//Initialise curl object
$ch = curl_init();

//Define curl options in an array
$options = array(CURLOPT_URL => "your-external-url",        
    CURLOPT_HEADER => "Content-Type:application/xml",        
    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
    CURLOPT_RETURNTRANSFER => TRUE
);

//Set options against curl object
curl_setopt_array($ch, $options);

//Assign execution of curl object to a variable
$data = curl_exec($ch);

//Close curl object
curl_close($ch);

//Pass results to the SimpleXMLElement function
$xml = new SimpleXMLElement($data);

print_r($xml);
  • I got this error String could not be parsed as XML. – mahmoudismail Apr 11 '16 at 6:40
  • The most likely cause of this error is that the XML data you are trying to process is not valid. Alternatively, the XML data may contain non-standard characters or use a different character set encoding. – Prashant Valanda Apr 11 '16 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.