【发布时间】:2022-01-27 00:37:51
【问题描述】:
如何在帖子 (JavaScript fetch()) 请求中发送表单参数?
例如
curl --form "avatar=@me.jpg" "https://example.com/api/v4/endpoint"
我尝试了以下代码:
const form = new FormData()
form.append("foo":"bar")
fetch( "https://someapi.org/api", {
method: 'POST',
headers:form
} )
.then( response => response.json() )
.then( response => {
console.log(response)
} );
}
这对我不起作用。
【问题讨论】:
-
您可能想在
body中使用FormData实例而不是headers -
@Phillip 我已经尝试过了,但是在我使用的 api 的 Node-API 中,我使用的是在 Deno/Web 中不存在的 form.getHeaders() 的标头中
标签: javascript typescript http fetch deno