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

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

WBOY
WBOYOriginal
2016-06-06 20:15:371019browse

以前没设计过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>

当然可以。

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

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

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

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

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

Statement:
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