Laravel HTTP x-www-form-urlencoded Request Body

Dec 08, 2022 · Snippet · 1 min, 117 words

Sometimes we need to send x-www-form-urlencoded form data. Most of the time, we get these types of errors:

  1. unsupported_grant_type
  2. 'grant_type' must be set

If you would like to send data using the application/x-www-form-urlencoded content type, you should call the asForm method before making your request:

$response = Http::withBasicAuth($client, $client_secret)
    ->post($endpoint, [
        'grant_type' => 'authorization_code',
        'code' => $request->code,
        'redirect_uri' => $redirect_url


No comments yet…