【发布时间】:2022-11-16 05:32:52
【问题描述】:
当我尝试发送 Guzzle-POST 时,总是返回错误:
{"errors":[{"code":"0","status":"400","title":"Bad Request","detail":"JSON 负载格式错误。"}]}
因为我没有看到任何错误,在数据数组本身内部,也许它可能是错误的标题信息?这是对我尝试添加新文章的 shopware 6 API 的简单 POST 请求。
$payload= [ 'headers' => [ 'Content-Type' => 'application/json', 'Accept' => 'application/json', ], 'form_params' =>[ "name" => "productname", "productNumber" => "101003", "stock" => 2, "taxId" => "50ee15989533451095c9d7e03d9ce479", "price" => [ [ "currencyId" => "b7d2554b0ce847cd82f3ac9bd1c0dfca", "gross" => 15, "net" => 10, "linked" => false ] ] ] ]; $response = $client->request('POST', 'http://shopware6.shop.de/api/product', $data );如果我使用 Postman 或 RESTer 或类似工具,我会得到一个肯定的结果,它有效。所以我想我错过了某事。在我的 guzzle-request 中(这是来自 https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyMzA4NTUy-product-data 的原始文档的副本)
我正在使用 guzzle 和 kamermans oauth2 中间件
一个简单的 GET 请求也可以工作:
$response = $client->request('GET', 'http://shopware6.shop.de/api/product/{productid}', [ 'headers' => [ 'Content-Type' => 'application/json', 'Accept' => 'application/json', ] ] );
【问题讨论】:
标签: post request guzzle shopware6