【问题标题】:The remote server returned an error: (400) Bad Request. Using Shopify API to post product with body_html远程服务器返回错误:(400) 错误请求。使用 Shopify API 发布带有 body_html 的产品
【发布时间】:2020-11-05 09:12:44
【问题描述】:

我正在使用 Shopify API 在 Shopify 上发布产品。当我在我的 http_request 的 body_html 中添加一个冗长的详细信息时(它以 JSON 格式获取数据)。我想给出包含特殊字符的完整细节请给我任何解决方案。

我的代码是这样的

 {"product":{"title":"Premium LCD Digital Multimeter","body_html":"Premium LCD Digital Multimeter

New Digital Multimeter is an electronic measuring instrument that combines all your most commonly used measurement functions into one unit. This Multimeter comes with measurement and testing functions for voltage, current, resistance, continuity (the connection between two points), testing diodes, and temperature

This Digital Multimeter is a must have testing tool for your toolbox, shed, garage, car trunk, etc. Its portability enables you to be able to take it with you wherever you go and provides you with a multitude of features that helps you achieve the best results every time

Features:

* LCD Display
* Auto power off
* Digital Multimeter
* Handheld Multimeter
* Great tool bag accessory
* Great hardware hacking and reverse engineering
* Portable and versatile, easy to carry around and fits neatly in your tool bag
* Multiple testing functions, diode testing, AC/DC testing, temperature, continuity
* Perfect for home DIY en","product_type":"","vendor":"Abdur Rehman","tags":"blue,green,red","options":[],"images":[
  {
    "src": "https://business.tradingzon.com/images/itemimages/15Json Turneryg1 (261).jpg"
  },
  {
    "src": "https://business.tradingzon.com/images/itemimages/15Json Turneryg2 (159).jpg"
  },
  {
    "src": "https://business.tradingzon.com/images/itemimages/15Json Turneryg3 (143).jpg"
  }
],"variants":[
  {
    "title": "Default Title",
    "barcode": "dsfsr4353",
    "inventory_quantity": 1,
    "option1": "Default Title",
    "price": 10.69,
    "weight": 0.4,
    "weight_unit": "kg",
    "sku": "JSN-YG-02-090",
    "grams": 400,
    "tracked": "true",
    "compare_at_price": 15.45, 
    "inventory_policy": "continue"
  }
]}}

【问题讨论】:

  • 这段代码代表的是json格式的http_request内容。

标签: json shopify shopify-api


【解决方案1】:

简单。您的描述字段的 JSON 格式不正确。没有换行符,您必须使用“\n”语法告诉 JSON 处理器这是一个换行符。一个有用的工具 - https://jsonlint.com/

【讨论】:

  • 这个 json 实际上是我检查过的文本格式。如果我更改了这个 Http_request 中的描述以缩短文本,它不会导致任何异常
  • 您发送的内容类型标头是什么?
  • request.ProtocolVersion = HttpVersion.Version10; request.Method = "POST"; byte[] postBytes = Encoding.UTF8.GetBytes(jsonstring); request.ContentType = "application/json; charset=UTF-8"; request.Accept = "application/json";
  • 如果你使用application/json; charset=UTF-8,你的数据应该被正确格式化为JSON ..注意换行符,它会起作用
猜你喜欢
  • 2018-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多