带有 JSON 数据的 PHP 返回未设置为对象错误实例的对象引用


PHP w/ JSON data returns Object reference not set to an instance of an object error

PHP脚本连接到第三方API,只需很少的文档(https://www.youvegotleads.com/webservices/documentation),从我不熟悉的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

我再次查看了它,这是他们 API 中的一个错误。