使用xml发送Post请求到rest api

时间:2016-04-10 21:33:09

标签: php xml api rest curl

我正在尝试向可联系性API发布请求。可以在http://dev.contactability.com/ping_post/v1/docs/contactability-api.html

找到文档

有一些示例xml可用于发出请求。所以,我尝试了一个例子,但api响应“ERROR错误请求XML验证失败。请检查XML并再试一次.0.00” 这意味着我的xml根据他们的api要求无效。 有人可以帮我节省一天的时间吗?

<?php
$file = '
<InsuranceRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<AffiliateInfo>
<PartnerID>3</PartnerID>
<Token>G15QncRptYzJftqUauVyodKvsoZWxArrhiukhbkjr</Token>
<TrackingCampaign>MyCampaign</TrackingCampaign>
<LeadSourceID>InHouse</LeadSourceID>
<ProductionEnvironment>true</ProductionEnvironment>
</AffiliateInfo>
<DistributionDirectives>
<Cap>5</Cap>
<DistributionCount>3</DistributionCount>
<Excludes>
<Exclude>
<CarrierName>Independent</CarrierName>
<LicenseNumber>4491903731590</LicenseNumber>
</Exclude>
<Exclude>
<CarrierName>Allstate</CarrierName>
</Exclude>
<Exclude>
<CarrierName>State Farm</CarrierName>
</Exclude>
</Excludes>
</DistributionDirectives>
<LeadTypeID>1</LeadTypeID>
<ZipCode>43215</ZipCode>
<ContactInfo>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Address>123 E Main St</Address>
<ZipCode>43215</ZipCode>
<City>Columbus</City>
<State>OH</State>
<PhoneDay>1234567890</PhoneDay>
<Email>johndoe@test.com</Email>
</ContactInfo>
<AutoInsurance>
<Vehicles>
<Vehicle>
<Id>1</Id>
<Vin>1G1JF31W*K*******</Vin>
<Year>1989</Year>
<Make>CHEV</Make>
<Model>CAVALIER Z24</Model>
<SubModel>_</SubModel>
<Owner>Leased</Owner>
<Garage>Private</Garage>
<PrimaryUse>Commute School</PrimaryUse>
<OneWay>85</OneWay>
<AnnualMileage>25000</AnnualMileage>
<Salvaged>false</Salvaged>
<Comprehensive>500</Comprehensive>
<Collision>2500</Collision>
</Vehicle>
<Vehicle>
<Id>2</Id>
<Vin>1FTZF08W*X*******</Vin>
<Year>1999</Year>
<Make>FORD</Make>
<Model>F150</Model>
<SubModel>_</SubModel>
<Owner>Owned</Owner>
<Garage>Private</Garage>
<PrimaryUse>Commute School</PrimaryUse>
<OneWay>62</OneWay>
<AnnualMileage>50000</AnnualMileage>
<Salvaged>true</Salvaged>
<Comprehensive>No Coverage</Comprehensive>
<Collision>250</Collision>
</Vehicle>
</Vehicles>
<Drivers>
<Driver>
<Id>1</Id>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<Gender>Male</Gender>
<Marital>Domestic Partner</Marital>
<DOB>1992-07-25</DOB>
<Relation>Self</Relation>
<DLicenseState>CT</DLicenseState>
<DLicenseStatus>Temporary</DLicenseStatus>
<LicensedAge>17</LicensedAge>
<VehicleId>1</VehicleId>
<Filing>false</Filing>
<Education>Doctorate Degree</Education>
<Occupation>Self Employed</Occupation>
<GoodStudent>false</GoodStudent>
<Suspension>false</Suspension>
</Driver>
<Driver>
<Id>2</Id>
<FirstName>Jane</FirstName>
<LastName>Doe</LastName>
<Gender>Female</Gender>
<Marital>Married</Marital>
<DOB>1988-07-25</DOB>
<Relation>Other</Relation>
<DLicenseState>ND</DLicenseState>
<DLicenseStatus>Probation</DLicenseStatus>
<LicensedAge>18</LicensedAge>
<VehicleId>2</VehicleId>
<Filing>false</Filing>
<Education>High School Diploma</Education>
<Occupation>Homemaker</Occupation>
<GoodStudent>false</GoodStudent>
<Suspension>false</Suspension>
</Driver>
</Drivers>
<Incidents>
<Ticket>
<DriverId>1</DriverId>
<Date>2010-06-25</Date>
<Description>Speeding</Description>
</Ticket>
<Ticket>
<DriverId>1</DriverId>
<Date>2010-10-30</Date>
<Description>Child Seat</Description>
</Ticket>
<Ticket>
<DriverId>2</DriverId>
<Date>2011-02-09</Date>
<Description>Other Ticket</Description>
</Ticket>
<Ticket>
<DriverId>2</DriverId>
<Date>2008-08-29</Date>
<Description>Failure to Stop</Description>
</Ticket>
<Ticket>
<DriverId>2</DriverId>
<Date>2011-02-15</Date>
<Description>Child Seat</Description>
</Ticket>
<Claim>
<DriverId>2</DriverId>
<Date>2010-06-26</Date>
<Description>Vandalism Damage</Description>
<PaidAmount>8300</PaidAmount>
</Claim>
<Claim>
<DriverId>2</DriverId>
<Date>2009-02-27</Date>
<Description>Loss Claim Not Listed</Description>
<PaidAmount>700</PaidAmount>
</Claim>
<Claim>
<DriverId>2</DriverId>
<Date>2009-04-24</Date>
<Description>Vehicle Stolen</Description>
<PaidAmount>6900</PaidAmount>
</Claim>
<Claim>
<DriverId>2</DriverId>
<Date>2010-06-06</Date>
<Description>Loss Claim Not Listed</Description>
<PaidAmount>8300</PaidAmount>
</Claim>
</Incidents>
<ApplicantInfo>
<Credit>Good</Credit>
<Residence>Own</Residence>
</ApplicantInfo>
<CurrentInsurance>
<CurrentlyInsured>true</CurrentlyInsured>
<CurrentPolicy>
<Carrier>Nationwide</Carrier>
<Expiration>2016-03-01</Expiration>
<InsuredSince>2015-01-01</InsuredSince>
</CurrentPolicy>
</CurrentInsurance>
<RequestedCoverage>Standard</RequestedCoverage>
</AutoInsurance>
</InsuranceRequest>
';
echo $file;
$url = 'http://staging.pingpost.contactability.com/api/v1/post';
$ch = curl_init();
  curl_setopt( $ch, CURLOPT_URL, $url );
  curl_setopt( $ch, CURLOPT_POST, true );
  curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
  curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  curl_setopt( $ch, CURLOPT_POSTFIELDS, $file );
  $result = curl_exec($ch);
  echo $result;
  curl_close($ch);
?>

0 个答案:

没有答案