gpt4 book ai didi

javascript - 向 Fluxpoint api 发送请求时出错

转载 作者:行者123 更新时间:2023-12-01 00:00:23 27 4
gpt4 key购买 nike

又是我...抱歉每天问这么多次,但我真的是个白痴。

所以基本上我正在尝试使用以下代码向 Fluxpoint api 发送请求:

async welcome(username, avatarurl, background, membercount, icon, backgroundname, filename){
let req = {}
req.username = username;
req.avatar = avatarurl;
if (background == null) {req.background = "#aaaaaa"} else {req.background = background}
if (membercount) req.members = "Member #"+membercount
if (icon) req.icon = icon
if (backgroundname) req.banner = backgroundname
console.log(req)
let usedClient = axios.create({
baseURL: apiUrls[0],
timeout: 5000,
headers: {
'Authorization': this.token,
'Content-Length': 0,
'Content-Type': 'application/json'
},
data: JSON.parse(req),
responseType: 'arraybuffer'
})
console.log(usedClient)
console.log(apiUrls[0]+api1endpoints[1])
let res = await usedClient.get(api1endpoints[1])
return res
}

这是我用来测试它的代码:

const fluxpoint = require('./index')
const Client = new fluxpoint.Client("my fluxpoint token")

async function tt(){
let t = await Client.welcome("Koro~ (Baka)#7963", "https://cdn.discordapp.com/avatars/304541381798658048/36806f6ae648b9ebc8303443b0be101c.png", "#FFFFFF", 1, "neko", "space")
console.log(t)
}
tt()

并且,这是 Fluxpoint api 发送给我的错误:

无法解析 json,输入不包含任何 JSON 标记。当 isFinalBlock 为 true 时,排除以有效 JSON token 开头的输入。路径: $ |行号: 0 |字节位置内联:0。

我尝试了所有方法,但 JSON.parse(我的数据) 向我发送了 JSON 中位置 1 处的无异常标记 o

我很绝望,希望有人能帮助我!

最佳答案

您似乎正在解析原始 json。它会抛出错误

JSON.parse 将字符串作为参数。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

根据官方文档,您不能在 get 请求中使用数据。

https://github.com/axios/axios#request-config

 // `data` is the data to be sent as the request body
// Only applicable for request methods 'PUT', 'POST', and 'PATCH'
// When no `transformRequest` is set, must be of one of the following types:
// - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
// - Browser only: FormData, File, Blob
// - Node only: Stream, Buffer
data: {
firstName: 'Fred'
}

所以尝试传递数据

let res = await usedClient.get(api1endpoints[1],{
params: {
data: res
}
})

我已经测试了端点,它仅在响应类型为“text”或“stream”时才起作用

关于javascript - 向 Fluxpoint api 发送请求时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60779437/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com