ixudra / curl

Custom PHP curl library for the Laravel 5 framework - developed by Ixudra

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Return Null

risidan opened this issue · comments

I'm trying to post in a local web service using this code

$params = array( 'config' => array(
            'format' => 'normal',
            'layout' => 'TOP'),
            'boletos' => array(
                array(
                'valor' => '15,00',
                'vencimento' => '10/01/2018',
                'banco' => '237',
                'agencia' => '123',
                'codBeneficiario' => '4567',
                'carteira'=>'09',
                'nossoNumero' => '25897'
            ))
        );

$response = Curl::to('http://localhost:9999/v1/boleto/')
                ->withData($params)
                ->asJson()
                ->enableDebug('../public/boletos/logFile.txt')
                ->post();

but the response is returning null, in the log file return this:

*   Trying ::1...
* Connected to localhost (::1) port 9999 (#0)
> POST /v1/boleto/ HTTP/1.1
Host: localhost:9999
Accept: */*
Content-Type: application/json
Content-Length: 193

* upload completely sent off: 193 out of 193 bytes
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Server: BoletoDireto-4.1.6.R1 (10/11/2017)
< Content-Type: application/pdf
< Content-Length: 4681
< 
* Connection #0 to host localhost left intact

should return something like a pdf.
What am I doing wrong?

using postman works perfectly

thanks in advance.

The ->asJson() causes the package to try and decode the response to a json object. If you're expecting a pdf, you should probably remove that and use the ->download() method instead, see here

The webservice expects a Json if I take that ->asJson() does not work, and if I try to set the response contentType-> withContentType ('application/pdf') it also does not work

try using the ->asJsonRequest() method instead. It submits the data as json but doesn't decode the response

Thanks, works perfectly, this was in the documentation and I did not see it, sorry, but now the response give to me this code: %PDF-1.4 %���� 5 0 obj <>stream, using the curl php seting header('Content-type: application/pdf'), convert this in a pdf file, how i can the same in ixudra/curl, i trying to use ->withHeader('ContentType: application/pdf') or ->withContentType('application/pdf') and does not work

When you open a pdf in a text editor, you get that kind of data. Try saving the data to file and open it with a PDF viewer

Thanks