Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/266861-curl-help/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.