【问题标题】:laravel client api with guzzlelaravel 客户端 api 与 guzzle
【发布时间】:2020-11-20 21:19:49
【问题描述】:

我正在使用来自 RapidAPI 面部验证https://rapidapi.com/HiBrainy/api/face-recognition4 的 API 和 我在使用 API 时遇到困难 此示例代码来自 RapidAPI 的 PHP

$client = new http\Client;
$request = new http\Client\Request;

$body = new http\Message\Body;
$body->addForm(array(
    'photo1' => array(
        'value' => 'image2.jpg',
        'data' => 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAQ=='
    ),
    'photo2' => array(
        'value' => 'image2.jpg',
        'data' => 'data:image/jpeg;base64,/9j/4AAQSkZ630QAMXaf//Z'
    )
), NULL);

$request->setRequestUrl('https://face-recognition4.p.rapidapi.com/FaceVerification');
$request->setRequestMethod('POST');
$request->setBody($body);

$request->setHeaders(array(
    'x-rapidapi-host' => 'face-recognition4.p.rapidapi.com',
    'x-rapidapi-key' => $my_api_key,
    'content-type' => 'multipart/form-data'
));

$client->enqueue($request)->send();
$response = $client->getResponse();

echo $response->getBody();

我用 guzzle 包申请了 laravel 我的代码

try {

...other code...

     $client = new Client();
     $response = $client->post('https://face-recognition4.p.rapidapi.com/FaceVerification', [
        'headers' => [
            'x-rapidapi-host' => 'face-recognition4.p.rapidapi.com',
            'x-rapidapi-key' => $my_api_key,
            'content-type' => 'multipart/form-data'
        ],
        'multipart' => [
            [
                'name' => 'photo1',
                'contents' => $image1,
                'filename' => 'image1.jpg'
            ],
            [
                'name' => 'photo2',
                'contents' => $image2,
                'filename' => 'image2.jpg'
            ]
        ]
    ]);
}catch (\Exception $error){
    dd($error);
}

我有错误

#message: """
        客户端错误:`POST https://face-recognition4.p.rapidapi.com/FaceVerification` 导致 `400 Bad Request` 响应:
        {"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"出现一个或多个验证错误。","status":4 (截断.. .)

【问题讨论】:

    标签: laravel api guzzle


    【解决方案1】:

    您应该考虑从您共享的代码中删除您的 API 密钥

    尝试查看原始请求以获取更多详细信息并验证您的请求格式是否正确

    【讨论】:

    • 是的...... api 密钥不正确我添加了一些字符串
    猜你喜欢
    • 2020-06-04
    • 2019-02-20
    • 2016-06-24
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 2021-01-06
    • 2021-12-26
    • 2015-06-09
    相关资源
    最近更新 更多