如何解决进行curl HTTP请求时,云函数给出错误400
如果我尝试使用json正文向云函数发出HTTP请求,则会收到错误消息。如果将body设置为'{}'
,则没有错误。如果我将主体设置为'{"test":"test"}'
,则会出现错误...另外,如果我将内容类型更改为text/plan
,它也可以正常工作。似乎JSON解析器正在解释我的JSON格式错误。请帮忙。谢谢
SyntaxError: Unexpected token n in JSON at position 1
at JSON.parse (<anonymous>)
at parse (/layers/google.nodejs.functions-framework/functions-framework/node_modules/body-parser/lib/types/json.js:89:19)
我的云功能:
import * as functions from 'firebase-functions';
export const helloWorld = functions.https.onRequest(async (request,response) => {
try {
functions.logger.info("req body",request.body)
response.send(request.body)
} catch (err) {
response.send("err")
console.log(err)
}
});
curl -d '{"test":"test"}' -H "Content-Type: application/json" myfirebaseurl
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。