尝试进行POST API调用,我得到错误file_get_contents(http://api.turfgame.com/v4/users):未能打开流:HTTP请求失败!HTTP/1.1 400错误请求。API信息可在http://api.turfgame.com
找到。<?php
$data = array("name" => "DIProgan");
$url = 'http://api.turfgame.com/v4/users';
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode( $data ),
'header'=> "Content-Type: application/json'r'n" .
"Accept: application/json'r'n"
)
);
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
$response = json_decode( $result );
var_dump($response);
?>
使用XAMPP &PHP 5.4.4。我尝试使用"请求PHP",因为我喜欢它的Python版本,但它只是抱怨找不到钩子函数。人们似乎讨厌cURL,从我需要它的那一点点开始,它似乎更容易没有它。也许不是。帮助吗?
似乎您刚刚创建了一个数组,您已经把您的参数。