使用非常少的文档(https://www.youvegotleads.com/webservices/documentation)连接到第三方API的PHP脚本从我不熟悉的API返回错误。我已经咨询并搜索过,并尝试实施几个建议的解决方案无济于事。
$host = "https://www.youvegotleads.com/api/properties/95774/leads";
$header = array();
$header[] = 'Content-Length: ' . strlen($data_string);
$header[] = 'Content-type: application/json';
$header[] = 'Accept: application/json';
$header[] = 'Authorization: Basic eWdsQXBpVGVzdDM6cGFzc3dvcmQ=';
$header[] = 'Hostname: https://www.youvegotleads.com';
//if($form["id"] == 1){//Join Our Mailing List
//$entry["6"]
$data = array(
"Veteran" => 'Yes',
"PrimaryContact" => array (
"FirstName" => "Tommy",
"LastName" => "Tuba",
"Address" => array (
"Email" => "tommy@tubas.com",
"PhoneHome" => "555-555-1212",
"PhoneCell" => "555-555-1313",
"PhoneWork" => "555-555-1414"
),
"DateOfBirth" => "07/18/1950"
),
);
//}
$data_string = json_encode($data);
$ch = curl_init($host);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// 3. execute and fetch the resulting HTML output
$output = curl_exec($ch);
echo "<pre>";
print_r($output);
echo "</pre>";
if ($output === FALSE) {
echo "cURL Error: " . curl_error($ch);
}
// 4. free up the curl handle
curl_close($ch);
从API返回错误:
{"Message":"An error has occurred.","ExceptionMessage":"Object reference not set to an instance of an object.","ExceptionType":"System.NullReferenceException","StackTrace":" at YouveGotLeads.Areas.WebServices.Controllers.LeadsController.PostLead(Int32 propertyId, L
答案 0 :(得分:0)
我再次对其进行了审核,其API中出现了错误。