我在将json对象发布到使用REST的API时遇到了一些困难.我是新手使用cURL,但我已经搜遍了所有人,试图找到我的问题的答案,但是已经做得很短.我的cURL请求总是返回false.我知道它甚至没有发布我的json对象,因为我仍然会从url获得响应.我的代码如下.
<?php
//API KEY = APIUsername
//API_CODE = APIPassword
$API_Key = "some API key";
$API_Code = "some API code";
$API_email = "email@email.com";
$API_password = "ohhello";
$url = "http://someURL.com/rest.svc/blah";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
header('Content-type: application/json');
$authData = "{\"APIUsername\":\"$API_Key\",\"APIPassword\":\"$API_Code\",\"EmailAddress\":\"$API_email\",\"Password\":\"$API_password\"}";
curl_setopt($ch, CURLOPT_POSTFIELDS, $authData);
//make the request
$result = curl_exec($ch);
$response = json_encode($result);
echo $response;
curl_close()
?>
Run Code Online (Sandbox Code Playgroud)
$ response返回"false"
有什么想法吗?