【发布时间】:2022-01-13 07:14:40
【问题描述】:
我正在尝试向 Laravel 应用程序发送带有 "Content-Type": "multipart/form-data" 的 HTTP PUT 请求。当我将方法更改为 POST 时,它可以工作。
$a = $request->all(); // With PUT this is empty but with POST it works fine.
客户端执行如下代码:
axios({
method: "post", // when I try method:"PUT" and change the content type
url: "/api/offer",
data: fd,
headers: {"Content-Type": "multipart/form-data"} // here change to "x-www-form-urlencoded" it the $a array on backend is empty!
}).then(response => {
console.log("/offer/" + response.data)
if (response.data)
window.location.replace("/offer/" + this.offer.id);
else {
console.log("show a message that something went wrong! ")
}
}).catch(function (error) {
})
我在 docs 中找不到 PUT 无法发送“multipart/form-data”的任何地方
那么,PUT 可以发送“multipart/form-data”还是只有 POST 一般可以这样做,或者它只是 PHP / Laravel 问题?
编辑: 另外,使用 PUT 代替 POST 与正确遵守 HTTP 协议和 CRUD 操作有什么区别?
【问题讨论】: