Home > Backend Development > PHP Tutorial > php一定要键值对的方式接受POST数据吗?他能不能接收全文本的数据?

php一定要键值对的方式接受POST数据吗?他能不能接收全文本的数据?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:15:37
Original
1087 people have browsed it

以前没设计过API 我想做个JSON的API,直接传递JSON过去,但是好像一定要键值对的方式传递,全文本的话$_POST接收不到东西.一定要键值对方式吗?

回复内容:

以前没设计过API 我想做个JSON的API,直接传递JSON过去,但是好像一定要键值对的方式传递,全文本的话$_POST接收不到东西.一定要键值对方式吗?

$jsoncode = file_get_contents("php://input");
$arr = array();
$arr = convertUrlQuery($jsoncode);

<code>$user_id = $arr['user_id'];
$info = $arr['info'];
$type  =$arr['type'];</code>
Copy after login

当然可以。

<code class="php">$data_one = $GLOBALS['HTTP_RAW_POST_DATA'];

$data_two = file_get_contents("php://input");</code>
Copy after login

可以用curl测试,核心语句。

<code class="php">curl_setopt($ch, CURLOPT_POSTFIELDS,"我没有名字");</code>
Copy after login

$postdata = file_get_contents("php://input");

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template