1

I'm testing an XML POST between two files:

  1. index.php, which writes out a simple xml to the page.

  2. send.php, which sends a curl POST to index.php and expects the xml response

The problem occurs when I open 'send.php' - the xml from index.php is not writing to the page. I suspect that I'm not writing out the xml properly, but could really use some guidance on this. My code is below:

// send.php
$url_request = 'index.php';

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url_request);
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
    $response = curl_exec($curl);
    curl_close($curl);

    $xml = simplexml_load_string($response);
    print_r($xml);

// index.php
header("Content-type: text/xml");

function sendResponse(){
    $response = '<?xml version="1.0" encoding="utf-8"?><response>success</response>';
    echo $response;
}

sendResponse();

1 Answer 1

1

You need to use the full path of the index.php file :

$url_request = 'http://localhost/path/to/index/index.php';

Besides, its is always good practice to use echo curl_error($curl); after curl_exec to track errors.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.