Tuesday, January 30, 2024

[SOLVED] Guzzle issue missing-input-secret & missing-input-response

Issue

I'm using Guzzle 6.5.0 with Laravel 6.7.0 When verifying Google reCaptcha via Guzzle it seems as if the Request Body / form_params are not included in the POST params. Below is the PHPUnit 8.5.0 output...

object(GuzzleHttp\Psr7\Request)#1179 (7) {
 ["method":"GuzzleHttp\Psr7\Request":private]=>
  string(4) "POST"
  ["requestTarget":"GuzzleHttp\Psr7\Request":private]=>
  NULL
  ["uri":"GuzzleHttp\Psr7\Request":private]=>
  object(GuzzleHttp\Psr7\Uri)#1180 (7) {
    ["scheme":"GuzzleHttp\Psr7\Uri":private]=>
    string(5) "https"
    ["userInfo":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
    ["host":"GuzzleHttp\Psr7\Uri":private]=>
    string(14) "www.google.com"
    ["port":"GuzzleHttp\Psr7\Uri":private]=>
    NULL
    ["path":"GuzzleHttp\Psr7\Uri":private]=>
    string(25) "/recaptcha/api/siteverify"
    ["query":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
    ["fragment":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
  }
  ["headers":"GuzzleHttp\Psr7\Request":private]=>
  array(3) {
    ["Host"]=>
    array(1) {
      [0]=>
      string(14) "www.google.com"
    }
    ["headers"]=>
    array(1) {
      ["Content-Type"]=>
      string(33) "application/x-www-form-urlencoded"
    }
    ["form_params"]=>
    array(2) {
      ["secret"]=>
      string(40) "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"
      ["response"]=>
      string(3) "123"
    }
  }
  ["headerNames":"GuzzleHttp\Psr7\Request":private]=>
  array(3) {
    ["headers"]=>
    string(7) "headers"
    ["form_params"]=>
    string(11) "form_params"
    ["host"]=>
    string(4) "Host"
  }
  ["protocol":"GuzzleHttp\Psr7\Request":private]=>
  string(3) "1.1"
  ["stream":"GuzzleHttp\Psr7\Request":private]=>
  object(GuzzleHttp\Psr7\Stream)#1182 (7) {
    ["stream":"GuzzleHttp\Psr7\Stream":private]=>
    resource(609) of type (stream)
    ["size":"GuzzleHttp\Psr7\Stream":private]=>
    int(0)
    ["seekable":"GuzzleHttp\Psr7\Stream":private]=>
    bool(true)
    ["readable":"GuzzleHttp\Psr7\Stream":private]=>
    bool(true)
    ["writable":"GuzzleHttp\Psr7\Stream":private]=>
    bool(true)
    ["uri":"GuzzleHttp\Psr7\Stream":private]=>
    string(10) "php://temp"
    ["customMetadata":"GuzzleHttp\Psr7\Stream":private]=>
    array(0) {
   }
 }

The Content-Type header was set manually. In Laravel, I have access to the secret and the URL so that is not the issue. Especially since the request is sent to the correct URL. Any help would be greatly appreciated.


Solution

here the issue explained / why it was not working:

I was confusing Client with Request options:

https://github.com/guzzle/psr7/issues/179

Hope this will help someone else!



Answered By - germanyDevelops
Answer Checked By - Marie Seifert (WPSolving Admin)