Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9137305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:05:15+00:00 2026-06-17T09:05:15+00:00

I am using a local server on my computer and i am trying to

  • 0

I am using a local server on my computer and i am trying to make 2 php scripts to send an xml file and receive it.

To send the xml file i use this code :

<?php
  /*
   * XML Sender/Client.
   */
  // Get our XML. You can declare it here or even load a file.
  $file = 'http://localhost/iPM/books.xml';
  if(!$xml_builder = simplexml_load_file($file))
  exit('Failed to open '.$file);

  // We send XML via CURL using POST with a http header of text/xml.
  $ch = curl_init();
  // set URL and other appropriate options
  curl_setopt($ch, CURLOPT_URL, "http://localhost/iPM/receiver.php");
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_builder);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
  curl_setopt($ch, CURLOPT_REFERER, 'http://localhost/iPM/receiver.php');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $ch_result = curl_exec($ch);
  curl_close($ch);
  // Print CURL result.
  echo $ch_result;
?>

To receive the xml file i use this code :

<?php
  /*
   * XML Server.
   */
  // We use php://input to get the raw $_POST results.
  $xml_post = file_get_contents('php://input');
  // If we receive data, save it.
  if ($xml_post) {
    $xml_file = 'received_xml_' . date('Y_m_d-H-i-s') . '.xml';
    $fh       = fopen($xml_file, 'w') or die();
    fwrite($fh, $xml_post);
    fclose($fh);
    // Return, as we don't want to cause a loop by processing the code below.
    return;
  }
?>

When i run the post script i get this error :

Notice: Array to string conversion in C:\xampp\htdocs\iPM\main.php on line 17

which refers to line :

curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_builder);

which i dont know what exactly does. The xml file i receive is created but when i open it i get this :

XML Parsing Error: syntax error
Location: file:///C:/xampp/htdocs/iPM/received_xml_2013_01_14-01-06-09.xml
Line Number 1, Column 1:

I tried to comment this specific line as i thought the problem lies there but then when i run my post script i get this error :

Request entity too large!

The POST method does not allow the data transmitted, or the data volume exceeds the capacity limit.

If you think this is a server error, please contact the webmaster. 

Error 413

but the xml file is only 5kbs so this is not the problem.

Does anyone have any idea what i should do here? All i am trying to do is make a script to send an xml file and a script to receive it and save it as an xml.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:05:16+00:00Added an answer on June 17, 2026 at 9:05 am

    curl_setopt($ch, CURLOPT_POSTFIELDS, $foo) sets your request’s body, the data to be posted. It expects $foo to be a set of key-value pairs provided either as an array:

    $foo = array(
        'foo' => 'some value',
        'bar' => 2
    );
    

    or as a percent-encoded string:

    $foo = 'foo=some%20value&bar=2'
    

    Instead, you’re providing $xml_builder variable which is a SimpleXMLElement object returned by simplexml_load_file($file).

    Try this:

    $postfields = array(
        'xml' => $your_xml_as_string; // get it with file_get_contents() for example
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    

    Then on the receiving end:

    $received_xml = $_POST['xml'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to use PHP mail on my local computer, but its just not
I successfully created database on my local server using Code First, migrated it to
I'm trying to make a Air server send files that server located on another
Is it safe to update DBF files using Advantage Local Server .Net provider whilst
I have a problem using a local SQL Server CE database with C# and
I wanted to deploy my app into my local server using apache and passenger.
I've created a custom CMS, and it works perfectly on a local server using
I have a really weird issue here. I'm using my local development server right
How can i sync sql server 2008-R2 (remopte server and local) using Microsoft Sync
I am using Hibernate with MySql, when i start my local server and pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.