ThinkPHP 中使用 Shopify Admin REST API 更新 fulfillment_line_item 返回 406 错误解决方案
在 ThinkPHP 中使用 Shopify 的 Admin REST API 更新 fulfillment_line_item 时,返回 406 表示请求的资源格式不被服务器接受。这通常是因为请求的内容类型(Content-Type)与服务器支持的内容类型不匹配。\n\n要解决这个问题,你可以检查请求的头部中的 Content-Type 是否正确设置为服务器支持的格式。对于 Shopify 的 Admin REST API,通常使用的是 application/json 作为 Content-Type。确保请求中的 Content-Type 设置正确,并且请求的主体数据也是正确的 JSON 格式。\n\n以下是一个示例代码片段,展示如何使用 ThinkPHP 发送更新 fulfillment_line_item 的请求:\n\nphp\nuse GuzzleHttp\Client;\n\n// 创建 GuzzleHttp 客户端\n$client = new Client();\n\n// 请求参数\n$data = [\n 'fulfillment_line_item' => [\n 'id' => 'fulfillment_line_item_id',\n 'quantity' => 2\n ]\n];\n\n// 发送请求\n$response = $client->request('PUT', 'https://your-shopify-store.myshopify.com/admin/api/2021-07/orders/order_id/fulfillments/fulfillment_id/fulfillment_line_items/fulfillment_line_item_id.json', [\n 'headers' => [\n 'Content-Type' => 'application/json',\n 'X-Shopify-Access-Token' => 'your_access_token'\n ],\n 'json' => $data\n]);\n\n// 获取响应\n$statusCode = $response->getStatusCode();\n$responseBody = $response->getBody()->getContents();\n\n// 处理响应\nif ($statusCode == 200) {\n // 更新成功\n echo 'Fulfillment Line Item updated successfully.';\n} else {\n // 更新失败\n echo 'Failed to update Fulfillment Line Item. Response: ' . $responseBody;\n}\n\n\n确保替换示例代码中的相关 URL 和参数为你自己的实际值,并使用正确的访问令牌(access token)进行身份验证。如果仍然遇到 406 错误,请检查请求的 Content-Type 和请求主体数据是否正确。
原文地址: https://www.cveoy.top/t/topic/qrme 著作权归作者所有。请勿转载和采集!