Hi, when I use Illuminate\Support\Facades\Http to make a post request to stable horde API
$response = Http::baseUrl(config('services.stablehorde.api_url'))
->withHeaders([
'accept' => 'application/json',
'Content-Type' => 'application/x-www-form-urlencoded',
])
->post('/register', [
'username' => $name,
]);
$content = $response->body();
I get errors like this :
<!doctype html>\n
<html lang=en>\n
<title>400 Bad Request</title>\n
<h1>Bad Request</h1>\n
<p>The browser (or proxy) sent a request that this server could not understand.</p>\n
but when I'm using curl, its works fine :
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, config('services.stablehorde.api_url') . '/register');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=$name");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);
<!DOCTYPE html>
<html>
<body>
<div class="container">
<div class="container">
<h1>Welcome</h1>
<h2>Set Display Name</h2>
.....
I don't want to use curl since I cannot test/mock the response. but I have no idea why the Laravel HTTP client throw and error. does anyone know why?