Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-24-2013, 09:29 PM   PM User | #1
surreal5335
Regular Coder

 
Join Date: May 2008
Posts: 446
Thanks: 23
Thanked 5 Times in 5 Posts
surreal5335 is an unknown quantity at this point
problem passing xml through curl

So I am trying to pass an xml string through curl onto a server. Currently what I am getting back is:

XML Parsing Error: not well-formed

if I turn off header type setting it to 'Content-type: text/xml' so now its just text/plain, i get:

415 Unsupported Media Type

I have gone through my xml string and tested seperatly to make sure the string I passing is good. It is, assigning the string as text/xml will produce a valid xml page without any errors. so it seems that my curl setup is to blame for this.

here is my code:

PHP Code:
$xmlToSend = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
        <order xmlns="http://sandbox.plimus.com">
         <soft-descriptor>DescTest</soft-descriptor>
           <ordering-shopper>
            <credit-card>
                          <card-last-four-digits>'.$cardLastFour.'</card-last-four-digits>
                          <card-type>'.$cardType.'</card-type>
                </credit-card>
              <shopper-id>'.$shopperId.'</shopper-id>
                    <web-info>
                        <ip></ip>         
                        <remote-host>bzq-219-121-253.static.bezeqint.net.reinventhosting.com</remote-host>
                        <user-agent>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.3; .NET CLR 2.0.50727)</user-agent>
                        <accept-language>en-us</accept-language>
                    </web-info>
           </ordering-shopper>
           <cart>
              <cart-item>
                 <sku>
                    <sku-id>'.$skuId.'</sku-id>
                 </sku>
                 <quantity>1</quantity>
                </cart-item>
           </cart>
           <expected-total-price>
              <amount>'.$amount.'</amount>
              <currency>'.$currency.'</currency>
           </expected-total-price>
        </order>
        ';

//echo $xmlToSend;


    $ch = curl_init();
    curl_setopt($ch, CURLOPT_MUTE, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_USERPWD, $credentials); 
    curl_setopt($ch, CURLOPT_URL, 'https://domain.com'); 
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlToSend);

$result = curl_exec($ch);
curl_close($ch);
echo $result;
all the variables in the code have values assigned to them, so dont worry about that part

Any ideas on what I am missing would be greatly appreciated
surreal5335 is offline   Reply With Quote
Old 01-24-2013, 11:46 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,641
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Guess it depends on precisely what is in those variables. If there's anything that disrupts the structure, that would blow it out of the water. Wrap them in cdata blocks to be sure.

The XML itself appears as well formed. Haven't a clue if its correct though.
If its fine for you, and its fine for me, than I'd suggest its where you're sending it that is tossing that error.

Curl wise, I guess that depends on what the server is doing. Its fine so long as they are pulling from the HTTP_RAW_POST_DATA. If they are not, than you will need to drop the content type as well as provide the input a fieldname in the post.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:31 PM.


Advertisement
Log in to turn off these ads.