应该以哪种格式创建访存POST请求以访问Imagga API?

问题描述 投票:0回答:1

我正在构建一个向用户推荐服装的移动应用程序。我正在使用Imagga's API来获取衣服的颜色,同时不包括背景。我已经尝试通过分析documentation中给出的node.js代码来使用访存发出POST请求:

image_file_b64 = "" + image_file_b64

//Extracting the colors from the object
  let response = await fetch('https://api.imagga.com/v2/colors', {  
    method: 'POST',
    headers: {
        'apiKey': '<PLACEHOLDER>',
        'apiSecret': '<PLACEHOLDER>',
        'Authorization': '<PLACEHOLDER>',
        Accept: 'application/json',
        'Content-Type': 'application/json',
    },
    body: JSON.stringify({
        image_base64: image_file_b64,
        extract_overall_colors: 0,
    })
})
let responseJson = await response.json()
console.log(responseJson)

但是,我收到的唯一输出是(最后一行记录的内容:]

Object {
  "status": Object {
    "text": "Please provide content for processing.",
    "type": "error",
  },
}

我已经与Imagga的某人合作解决了这个问题,但是他对本机反应并不熟悉。他建议将内容类型更改为“ application / x-www-form-urlencoded”或“ application / x-www-form-urlencoded; charset = UTF-8”,但均无济于事。

我相当有信心,问题出在我设置提取的方式上。如果有人熟悉Imagga API,可以请您确定代码中有什么错误或Imagga期望的内容与我提供的内容之间的格式不匹配,从而导致它不认为我已输入了该内容。谢谢!

我正在构建一个向用户推荐服装的移动应用程序。我正在使用Imagga的API来获取衣服的颜色,同时不包括背景。我试图发出POST请求...

node.js rest react-native fetch-api
1个回答
0
投票

提取主体不正确,您使用的Content-Type是JSON,为什么要发送字符串。对其进行如下修改,然后尝试。

© www.soinside.com 2019 - 2024. All rights reserved.