We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon Http client body response problem

I want to consume a webservice in my phalcon application then I seen the Phalcon's curl http client.

I use it like this :

        $provider = CRequest::getProvider();

        $provider->setBaseUri('https://example.com/api/');

        $provider->header->set('Accept', 'application/xml');

        $response = $provider->post('getUsers', [
            'myparams'  => 'paramsValue',
            ...
        ]);

        echo $response->body;

But I have a problem when I'm using $response->body. This will returns me the header and the body at the same time and I can't get the value of my XML.

HTTP/1.1 200 OK
Server: nginx
Date: Wed, 28 Sep 2016 16:14:34 GMT
Content-Type: application/xml
Content-Length: 25
Connection: keep-alive
Status: 200 OK

<id>62</id>

How can I do to get just the XML ?



79.0k
Accepted
answer

Why don't you use just curl? You can then have full control over entire API calls.

Perhaps somebody here could help you with that Incubator stuff, I always use curl for heavy stuff / production, and for testing even raw php.

edited Sep '16

Oh yeah you'r right :). Thanks a lot.

edited Sep '16

You're welcome. Sometimes plain & simple thing is best option for the task :)

For instance, just today I needed quick debug of the entire stack (complex back-end system) which I developed years ago using PHP with cURL. And there you go.

Folks working with OSB (Java) have never saw their raw API request like this :D

================ REQUEST HEADER ================
POST /endpoint/proxy/URegDsig HTTP/1.1
User-Agent: Ares III v4.27
Host: 10.20.50.250:8008
Accept: */*
Content-Type: application/soap+xml; charset=utf-8
X-Powered-By: Ares III
X-Powered-By-OS: Debian/GNU Linux 6.0.10
X-Powered-By-MIDDLEWARE: PHP 5.3.3-7+squeeze28 with Suhosin-Patch (cli) (built: Nov  8 2015 18:16:13)
X-Powered-By-BACKEND: MicroFocus COBOL V5.1 revision 0 build 10/10/2 G; 32409. Run Time System RXCVF/AA0/00000N
Content-Length: 4297
Expect: 100-continue

========== REQUEST BODY ===========
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="https://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/><soapenv:Body>
....
....

================ RESPONSE ================
HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Date: Thu, 29 Sep 2016 11:56:03 GMT
Content-Length: 3335
Content-Type: text/xml; charset=utf-8
X-Powered-By: Servlet/2.5 JSP/2.1

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="https://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/><soapenv:Body>
....
....

================ DETAILS ================

    [url] => https://10.20.50.250:8008/endpoint/proxy/URegDsig
    [content_type] => text/xml; charset=utf-8
    [http_code] => 200
    [header_size] => 177
    [request_size] => 500
    [filetime] => -1
    [ssl_verify_result] => 19
    [redirect_count] => 0
    [total_time] => 0.933123
    [namelookup_time] => 4.3E-5
    [connect_time] => 0.004304
    [pretransfer_time] => 0.060428
    [size_upload] => 4297
    [size_download] => 3335
    [speed_download] => 3574
    [speed_upload] => 4604
    [download_content_length] => 3335
    [upload_content_length] => 4297
    [starttransfer_time] => 0.069172
    [redirect_time] => 0
    [certinfo] => Array
        (
        )