这是代码。 我正在使用rest api和http身份验证来验证用户身份。 在运行该功能时,没有显示任何内容。 我没有从响应中获得成功/错误。响应为空,也没有错误。请帮忙
<?php
$method = "POST";
$url = "https://www.myproject.com/api/v1/projects/create";
$data_array = array("projectName"=>"Project1");
$data = json_encode($data_array);
$response = CallAPI($method,$url,$data);
function CallAPI($method, $url, $data)
{
$curl = curl_init();
switch ($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if ($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
default:
if ($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
// Optional Authentication:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
//base64
curl_setopt($curl, CURLOPT_USERPWD, "anemail@gmail.com:arpit.1995");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
$response = CallAPI($method,$url,$data);
echo $response;
?>