首页 > 解决方案 > `409 Conflict` 响应:{"code":"MissingParameter","message":"您必须提供用户密钥。"}

问题描述

所以我在搞乱Marvel API,我一直收到这个错误,我在任何地方都找不到它的任何痕迹。

`409 Conflict` response: {"code":"MissingParameter","message":"You must provide a user key."} 

我已经检查了 API 文档,但找不到有关用户密钥的任何信息。

这是我的代码;我正在使用 Laravel 和 Guzzle。

$res = $client->request('GET', 'http://gateway.marvel.com:80/v1/public/comics', [
        'apikey' => $apikey,
        'ts' => $now,
        'hash' => md5($now . $privateKey . $apikey),

    ]);

任何帮助将不胜感激。

标签: laravelrestapi

解决方案


尝试使用http_build_query

$query = http_build_query([
     'apikey' => $apikey, 
     'ts' => $now, 
     'hash' => md5($now . $privateKey . $apikey)
]);

$url = 'http://gateway.marvel.com:80/v1/public/comics?' . $query;

$res = $client->request('GET', $url);

更新

看起来您只需要在请求中设置查询选项。

$res = $client->request('GET', 'http://gateway.marvel.com:80/v1/public/comics', [
    'query' => [
        'apikey' => $apikey, 
        'ts' => $now, 
        'hash' => md5($now . $privateKey . $apikey)
    ]
]);

推荐阅读