frobak Posted August 9, 2012 Share Posted August 9, 2012 Hi I am tryign to connect to a web service through curl. I need to send a soap header with user/pass details, and then send the request with a further var and user/pass. I've been mucking around with this for ages now and need some help if possible. Im getting error "Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Start tag expected, '<' not found" I assume because its not returning xml, but even when i try to just print the respose without using simpleXMLelement i get an error about data is invalid. The code should return xml This is the code i have: // capture vehicle registration from main script $vehicle_reg = $_POST['add_vehicle_reg']; // convert reg to uppercase, remove spaces $vehicle_reg = strtoupper($vehicle_reg); $vehicle_reg = str_replace(' ', '', $vehicle_reg); define('NEWLINE', "<br />\n"); $ch = curl_init(); $data = '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <ServiceAuthHeader xmlns="http://example.com/"> <Username>username</Username> <Password>password</Password> </ServiceAuthHeader> </soap:Header> <soap:Body> <Vehicle_GetVehicleAndComponentParts xmlns="http://hosturl.com"> <vrm>' . $vehicle_reg . '</vrm> <userName>username</userName> <encryptedPassword>password</encryptedPassword> </Vehicle_GetVehicleAndComponentParts> </soap:Body> </soap:Envelope>'; curl_setopt($ch, CURLOPT_URL, 'http://www.example.com'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); // EXECUTE 1st REQUEST $postresponse = curl_exec ($ch); $veh_make = new SimpleXMLElement($postresponse); curl_close($ch); Am i like, miles away. Should i go back to school? Quote Link to comment https://forums.phpfreaks.com/topic/266861-curl-help/ Share on other sites More sharing options...
peipst9lker Posted August 9, 2012 Share Posted August 9, 2012 Yep go back to school Have you checked the output ? Take care that SimpleXML can't handle XML with namespaces! Quote Link to comment https://forums.phpfreaks.com/topic/266861-curl-help/#findComment-1368102 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.