我需要使用http post後返回的數據的幫助。 下面是我目前的職位代碼,並將數據到特定的網站收集和使用從http返回的數據Curl(php)Post
<?php
//extract data from the post
extract($_POST);
//set POST variables
$url = 'https://test.com';
$fields = array(
'surname' => urlencode($surname),
'first_name' => urlencode($first_name),
'dob' => urlencode($dob),
'email' => urlencode($email),
'home_phone' => urlencode($home_phone),
'mobile_phone' => urlencode($mobile_phone),
'work_phone' => urlencode($work_phone),
'postcode' => urlencode($postcode),
'leadid' => urlencode(123),
'affid' => urlencode(123),
'subid' => urlencode(123),
'bank_acno' => urlencode($bank_acno),
'bank_sort' => urlencode($bank_sort),
'amount_required' => urlencode($amount_required),
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>
我得到的2響應的任何一個 - {結果:TRUE}或{結果:假}
我需要知道的是如何做到以下幾點:
當我拿到{結果:真正}我想重定向到URL「http://thisurl.com」 當我拿到{結果:假}我要回一個響應「拒絕」
請注意th e響應不是json,它只是以這種格式返回。
是返回的數據真正的json?順便說一下,你可能希望看看PHP文檔中的http_build_query用於構建你的發佈數據 – RamRaider