gpt4 book ai didi

php - 使用 Axios 和 CodeIgniter 发送带有 JSON 的 POST 请求

转载 作者:搜寻专家 更新时间:2023-10-31 20:57:35 25 4
gpt4 key购买 nike

我正在尝试使用 Axios 发送数据:

axios.post( url,JSON.stringify({'i': '90'}))
.then(function (response) {
console.log(response);
});

并在服务器上获取它:

var_dump(($this->input->post())); // Returns an array |  $_POST

对于上面的 JSON 值,我得到了这样的响应:

array(2) { ["{"i":"90"}"]=> string(0) "" [0]=> string(0) "" }

没有 JSON.stringify,结果来自 var_dump(($this->input->post()));$_POST 是空数组。

如何用Axios发送带有JSON数据的POST请求,并用PHP在服务器上获取?

最佳答案

我遇到了同样的问题,最后发现是因为XSS Filtering,使用

   $i = $this->input->post("i",false);

在 axios 中使用 so

var formdata=new FormData();
formdata.append("key",value);

this.axios.post("http://URL",formdata).then(res=>{})

关于php - 使用 Axios 和 CodeIgniter 发送带有 JSON 的 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53974284/

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