且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有 JSON 字典的 POST 请求在 Swift 3 中使用 $_POST 没有返回正确的值?

更新时间:2023-08-20 12:39:10

参见 $_POST 文档 说的是:

See the $_POST documentation which says it is:

使用 application/x-www-form-urlencodedmultipart/form 时通过 HTTP POST 方法传递给当前脚本的关联变量数组-data 作为请求中的 HTTP Content-Type.

An associative array of variables passed to the current script via the HTTP POST method when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request.

但你不是在执行 x-www-form-urlencoded 请求.您正在执行 application/json 请求.所以你不能使用 $_POST.使用 php://input (例如,正如这里所讨论的:iOS 发送 JSON 数据在使用 NSJSONSerialization 的 POST 请求中).

But you're not doing x-www-form-urlencoded request. You're performing an application/json request. So you can't use $_POST. Use php://input (e.g., as discussed here: iOS Send JSON data in POST request using NSJSONSerialization).