【发布时间】:2017-05-31 02:02:12
【问题描述】:
我想连接到 API。但我需要通过 post 发送数据,但在 json 中接收。
<?php
$params = array (
'user_name' => '1521',
'user_password' => '8554',
'webservice_user'=>'test',
'token'=>'202cb962ac59075b964b07152d234b70');
$query = http_build_query ($params);
$contextData = array (
'method' => 'POST',
'header' => "Connection: close\r\n".
"Content-Length: ".strlen($query)."\r\n",
'content'=> $query );
$context = stream_context_create (array ( 'http' => $contextData ));
// Read page rendered as result of your POST request
$json = file_get_contents('url_here');
$obj = json_decode($json);
echo $obj->access_token;
$result = file_get_contents (
'IP_ex/login',
false,
$context);
echo($result);
?>
当我运行我的代码时,收到该错误:
file_get_contents(url_here):打开流失败
【问题讨论】: