作者:小永远佳瞳_186 | 来源:互联网 | 2023-10-11 10:24
我在Laravel 6.7.0中使用Guzzle 6.5.0,通过Guzzle验证Google reCaptcha时,似乎请求正文/ form_params
未包含在POST参数中。下面是PHPUnit 8.5.0的输出...
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) {
}
}
Content-Type
标头是手动设置的。在Laravel中,我可以访问机密和URL,所以这不是问题。特别是因为请求已发送到正确的URL。任何帮助将不胜感激。
小添加-使用TRUE选项将JSON解码后的响应转储为
PHPUnit 8.5.0 by Sebastian Bergmann and contributors.
...Array
(
[success] =>
[error-codes] => Array
(
[0] => missing-input-response
[1] => missing-input-secret
)
)
F 4 / 4 (100%)
Time: 2.46 seconds,Memory: 18.00 MB
,
问题在这里说明/为什么不起作用:
我使客户端与请求选项混淆:
https://github.com/guzzle/psr7/issues/179
希望这对其他人有帮助!