nategood / httpful

A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.
MIT License
1.74k stars 299 forks source link

error ? #218

Open cassolatto opened 8 years ago

cassolatto commented 8 years ago

I used this code: <?php $token = $_POST['token']; $dataini = $_POST['dataini']; $datafin = $_POST['datafin']; $veiculo = $_POST['veiculo']; include('httpful.phar');

$url = "http://apiv1.multiportal.com.br:9870/veiculos/periodo";

$response = \Httpful\Request::post($url) ->expectsJson() ->addHeader('content-type','application/json') ->addHeader('token',$token) ->addHeader('dataInicial',$dataini) ->addHeader('dataFinal' ,$datafin)
->body('{"veiculo":"'.$veiculo.'}') ->send(); echo $response;
?>

and given me this error message ( long ):

"
Fatal error: Uncaught exception 'Exception' with message 'Unable to parse response as JSON' in phar:///home/fastmobi/public_html/bredabus/httpful.phar/Httpful/Handlers/JsonHandler.php:30 Stack trace: #0 phar:///home/fastmobi/public_html/bredabus/httpful.phar/Httpful/Response.php(107): Httpful\Handlers\JsonHandler->parse('<html><body><h1...') #1 phar:///home/fastmobi/public_html/bredabus/httpful.phar/Httpful/Response.php(46): Httpful\Response->_parse('<html><body><h1...') #2 phar:///home/fastmobi/public_html/bredabus/httpful.phar/Httpful/Request.php(230): Httpful\Response->__construct('<html><body><h1...', 'HTTP/1.1 400 Ba...', Object(Httpful\Request), Array) #3 /home/fastmobi/public_html/bredabus/mmposicaoveiculos.php(17): Httpful\Request->send() #4 {main} thrown in phar:///home/fastmobi/public_html/bredabus/httpful.phar/Httpful/Handlers/JsonHandler.php on line 30
"

some help ?

Thanks in advance !

bigbigant commented 8 years ago

The serverside responses 400 error.

cassolatto commented 8 years ago

What this means ?

bigbigant commented 8 years ago

Just check the service http://apiv1.multiportal.com.br:9870/veiculos/periodo It does't response a normal json entity. Instead of that the service reponses an error message and it's not a json.

cassolatto commented 8 years ago

thank you very much

RICARDO CASSOLATTO

Business Consultant sintetik@gmail.com / 21 98196-0504

FastMobile http://fastmobile.info Rua Farani, 23 - apto. 403 - Botafogo - CEP 22231-020 - RJ - BRASIL

http://www.facebook.com/ricardo.cassolatto https://br.linkedin.com/in/ricardo-cassolato-9ba225

2016-03-08 23:48 GMT-03:00 Qing Zhao notifications@github.com:

Just check the service http://apiv1.multiportal.com.br:9870/veiculos/periodo It does't response a normal json entity. Instead of that the service reponses an error message and it's not a json.

— Reply to this email directly or view it on GitHub https://github.com/nategood/httpful/issues/218#issuecomment-194086554.