我正在尝试发出帖子请求并收到此异常:
"unsupported BodyInit type"
我认为问题在于请求的主体。 phoneNumbers
采用phoneNumbers = ["1234567890","1234567891"]
的形式(即字符串列表)。我尝试将JSON.stringify(phoneNumbers)用作正文,但是即使列表不为空,也似乎返回“ []”。
export async function findUsersByPhoneNumbersnotFollowing(userId,phoneNumbers) {
const reqConfig = {
method: 'POST',headers: {
'Content-Type': 'application/json',accept: 'application/json',},body: phoneNumbers,};
const response = await authfetch(`${API_URL}/following/recommendations/${userId}`,reqConfig);
if (response.error) {
throw new Error(response.error);
}
return response;
}
我要去哪里错了? API端点期望List<String>
(使用spring框架,并且controller方法在带注释的@RequestBody
中使用此参数)