ebanx-integration / ebanx-php

EBANX PHP Library
BSD 3-Clause "New" or "Revised" License
23 stars 11 forks source link

failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request #6

Open sstable opened 6 years ago

sstable commented 6 years ago

Hi, This SDK has a bug.

PHP Warning:  file_get_contents(https://sandbox.ebanx.com/ws/request): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
 in /data/aa/aa/vendor/ebanx/ebanx/src/Ebanx/Http/Client.php on line 154
PHP Fatal error:  Uncaught RuntimeException: Bad HTTP request:  in /data/aa/aa/vendor/ebanx/ebanx/src/Ebanx/Http/Client.php:166
Stack trace:
#0 /data/aa/aa/vendor/ebanx/ebanx/src/Ebanx/Command/AbstractCommand.php(91): Ebanx\Http\Client->send()
#1 /data/aa/aa/vendor/ebanx/ebanx/src/Ebanx/Ebanx.php(64): Ebanx\Command\AbstractCommand->execute(Array)
#2 /data/aa/aa/vendor/ebanx/ebanx/examples/checkout.php(11): Ebanx\Ebanx::__callStatic('doRequest', Array)
#3 {main}
  thrown in /data/aa/aa/vendor/ebanx/ebanx/src/Ebanx/Http/Client.php on line 166

How to reproduce the bug

  1. Set key to the file. example/bootstrap.php

  2. run php checkout.php

How to fix that.

  1. Open & find function send in Client.php file.

  2. change $context http -> header array to

 "Content-Type: application/x-www-form-urlencoded \r\n" .
 "User-Agent: EBANX PHP Library " . \Ebanx\Ebanx::VERSION . "\r\n" 

:)

mviniciusca commented 6 years ago

Straight to the point! Thanks @instadart