发布xml数据并获取xml响应

时间:2013-06-01 04:36:14

标签: php javascript xml json

我有一个网站,我想支持pingbid.net的API,我需要发布所需的数据并获取xml。有没有人有示例代码?

这是我的代码有人帮助我

<?php
$url ="https://pingbid.net/leads/add.xml";
$post_string ="api_key=**************************&group_id=***&client_ip=82.173.1.12&loan_amount=$100&gender=male&salutation=Mr&first_name=accept&last_name=Pipon&email=suzy@smith.com&alternate_email=suzy@smith.com&ssn=486351865&date_of_birth=1981-09-30&address1=123 Main Street&address2=Suite 101&city=Centralia&state=WA&zip=98531&country_code=US&phone_home=8181231234&phone_work=8181231234&phone_work_extension=201&mobile=8181231234&fax=8181231234&is_military=0&drivers_license_state=WA&drivers_license_number=28375781WA&own_home=1&months_at_address=24&monthly_residence_cost=8000&income_type=employment&job_title=Web Developer&pay_per_period=8000&monthly_income=8000&pay_frequency=twicemonthly&pay_day1=1981-09-30&pay_day2=1981-09-30&employer_name=Mercy West&employer_address=888 Second St&employer_city=Olympia&employer_state=WA&employer_zip=98101&months_employed=12&supervisor_name=Mary Jones&supervisor_phone=8181231234&supervisor_phone_ext=200&bank=HSBC&bank_phone=8181231234&months_at_bank=12&bank_routing_number=123456789&bank_account_number=12345678901873&bank_account_type=savings&direct_deposit=1&referer_first_name1=Joe&referer_last_name1=Stuart&referer_phone1=8181231234&referer_relation1=1&referer_first_name2=Joe&referer_last_name2=Stuart&referer_phone2=8181231234&referer_relation2=0&contact_time=2&sms_optin=0&originating_url=http://paydayloansonline1.com/cgi-bin/htmlos.cgi/apply_now/add_customer_info.html&client_url=http://paydayloansonline1.com/&is_live=0&subid=83773";

$ca = 'C:\AppServ\www\apply_php\cacert.crt';



$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_CAINFO, $ca);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 10);
$json = curl_exec($ch);
if(!$json) {
echo curl_error($ch);
}
curl_close($ch);

$xml = simplexml_load_string($json); 

$services = $xml->response;



print_r($json);

?>

这是样本回复:

<response>
<psid>6261398</psid>
<date>2013-05-31</date>
<name>accept Pipon</name>
<email>suzy@smith.com</email>
<status>accepted</status>
<message>Example acceptance message</message>
<network>Example network name</network>
<network_lead_id>12345</network_lead_id>
<price>1.23</price>
<redirect_url>https://pingbid.net/success.htm</redirect_url>
</response>

因为我在结果上面运行php代码只显示这个<psid><network_lead_id><price>

6261398123451.23

1 个答案:

答案 0 :(得分:0)

您需要尝试

curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);

然后你的回复返回0 像curl_getinfo()输出一样: -

 print_r($json); $info=curl_getinfo($ch);
   print_r($info);
0  Array ( [url] => https://pingbid.net/leads/add.xml [content_type] => text/xml [http_code] => 200 [header_size] => 325 [request_size] => 157 [filetime] => -1 [ssl_verify_result] => 20 [redirect_count] => 0 [total_time] => 1.605 [namelookup_time] => 0 [connect_time] => 0.263 [pretransfer_time] => 0.854 [size_upload] => 1473 [size_download] => 243 [speed_download] => 151 [speed_upload] => 917 [download_content_length] => 243 [upload_content_length] => 1473 [starttransfer_time] => 1.119 [redirect_time] => 0 )

所以尝试在网址上返回一些输出或尝试

CURL returns response code 200 and 0 for a same page at different time