【问题标题】:Stock update using REST API PUT Method gives error 'Invalid content type' Magento 2使用 REST API PUT 方法进行库存更新会出现错误“内容类型无效”Magento 2
【发布时间】:2018-08-14 15:18:52
【问题描述】:

我正在使用 magento2 Rest API 通过 sku 更新产品数量并在邮递员上进行测试,它给出了错误

Content-Type 标头无效。400 错误请求。

我已经生成了消费者密钥、消费者密钥、访问令牌和访问令牌密钥。

下面是postman中的设置-:

方法:PUT

网址http://127.0.0.1/pos_mage/rest/V1/products/{sku_of_product}

授权:OAuth2.0并设置访问令牌值

Header:键:Content-Type 和值:application/json

正文:键:stockItems 和值:10

但是当我尝试运行 API 时,它给了我错误

{ "message": "Content-Type 标头无效。" } 400 错误请求。

我正在本地主机上进行测试。

我检查了很多教程,但仍然没有成功-:

Magento 2 - REST API PUT product

Why "Invalid Content Type"

Magento 2 Updating Stock via Rest API

【问题讨论】:

    标签: php rest magento magento2.2


    【解决方案1】:

    在带有 JSON 负载的 REST API 的情况下,根据服务的 API 规范,400 错误代码通常用于指示 JSON 在某种程度上是无效的。

    检查请求是否包含有效的 JSON 格式或尝试以下操作:

    ContentType = "application/json" and Accept = "Application/json"
    

    【讨论】:

    • 感谢 Radwan,但您分享的解决方案不起作用。
    猜你喜欢
    • 2022-01-27
    • 1970-01-01
    • 2017-06-16
    • 2017-04-29
    • 1970-01-01
    • 2022-06-30
    • 2020-09-04
    • 2018-06-12
    • 1970-01-01
    相关资源
    最近更新 更多