Я хочу подключиться к API.but мне нужно отправить данные с сообщением, но получить в json.как отправить данные с помощью POST и получить с помощью json в php
<?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): failed to open stream
Возможный дубликат [Отправить json post с помощью php] (http://stackoverflow.com/questions/6213509/send-json-post-using-php) – bashoogzaad