0

I managed to get a SOAP client working for a client but I am now trying to use REST for a slightly different project. I am using Httpful. From what I have read it is what I need in order to do what I've been asked.

This is my code so far.

/* MAIN RESTFUL */

$xml_file = './Project.xml';
$xsd_file = './Project.xsd';
$end_uri = 'https://****.com/Service.svc/CreateProject';

/* TEMP TEXTAREA FIELD */

if(!isset($_POST['submit']))
    $_xml = file_get_contents($xml_file);
else
    $_xml = $_POST['xml_input'];

echo '<form method="post" action=""><textarea name="xml_input" rows="10" cols="100">' . $_xml . '</textarea><br /><input type="submit" name="submit" value="Send"></form><br /><a href="./">Reset Form</a><br /><br />';

/* END TEMP TEXTAREA FIELD */

if(isset($_POST['submit']))
    $xml_file = $_POST['xml_input'];

if(isset($_POST['submit']))
{
    $xsd_validate = new DOMDocument();
    $xsd_validate->loadXML($xml_file);

    if($xsd_validate->schemaValidate($xsd_file))
        $sendXML = true;

    if($sendXML == true)
    {
        require('./httpful-master/bootstrap.php');

        $request = \Httpful\Request::post($end_uri)
            ->body($xml_file)
            ->sendsXml()
            ->send();

        if($request)
            echo 'SENT!';
    }
}

The guy I am working with doesn't really know a lot about REST either but apparently there is a way to retrieve a response from the request being sent. Does anyone know, or at least can point me in the right direction, to solve this?

Thanks.

EDIT: Sorry, just to elaborate. The XML is placed into the textarea field then validated against an XSD file. If this is successful it will then post that XML to the REST endpoint.

1 Answer 1

2

the return value from the send call (named $request in your code) is actually a Httpful::Response Object and contains the response from your http-call.

Try echo $request->body; instead of echo 'SENT!';

And remember to always write the block for if-expressions, you can create hard to find bugs by skipping it :)

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

1 Comment

Sorry for the late reply but that worked exactly how it was meant to. Thanks!

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.