diff --git a/src/Transport/HttpTransport.php b/src/Transport/HttpTransport.php index 0409802..d09015d 100644 --- a/src/Transport/HttpTransport.php +++ b/src/Transport/HttpTransport.php @@ -73,6 +73,7 @@ protected function createRequestPayload(string $method, array $params = []): arr protected function sendHttpRequest(array $payload): Response { return Http::timeout($this->getTimeout()) + ->acceptJson() ->when( $this->hasApiKey(), fn ($http) => $http->withToken($this->getApiKey()) diff --git a/tests/Unit/Transport/HttpTransportTest.php b/tests/Unit/Transport/HttpTransportTest.php index 701ca77..889e4b5 100644 --- a/tests/Unit/Transport/HttpTransportTest.php +++ b/tests/Unit/Transport/HttpTransportTest.php @@ -183,3 +183,22 @@ expect($result)->toBeArray(); }); + +it('sends requests with JSON Accept header', function (): void { + $transport = new HttpTransport([ + 'url' => 'http://example.com/api', + 'timeout' => 30, + ]); + + Http::fake([ + 'http://example.com/api' => Http::response([ + 'jsonrpc' => '2.0', + 'id' => '1', + 'result' => ['status' => 'success'], + ]), + ]); + + $transport->sendRequest('test/method'); + + Http::assertSent(fn ($request) => $request->hasHeader('Accept', 'application/json')); +});