嗨,我有一個下面的代碼有問題。獲取JSON結果到一個PHP數組與POST請求
我使用curl登錄到網站。然後我去到sub併發送POST請求以JSON格式獲得結果。不幸的是,結果我得到:NULL
// options
$EMAIL = '...';
$PASSWORD = '...';
$cookie_file_path = "cookies/cookies.txt";
$LOGINURL = "https://www.domainname.com/auth/login";
$agent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36";
$ch = curl_init();
$headers[] = "Accept: */*";
$headers[] = "Connection: Keep-Alive";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$fields = array();
$fields['username'] = $EMAIL;
$fields['password'] = $PASSWORD;
$POSTFIELDS = http_build_query($fields);
curl_setopt($ch, CURLOPT_URL, $LOGINURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $POSTFIELDS);
$result = curl_exec($ch);
$params = array(
'akcja' =>'test1',
'Bank' =>'null',
'Produkt' =>'test2',
'ProwKOd' =>'undefined',
'domainKey'=>'326',
);
$remotePageUrl = 'http://www.domainname.com/users/Links';
curl_setopt($ch,CURLOPT_POST,count($params));
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_URL, $remotePageUrl);
$result = curl_exec($ch);
curl_close($ch);
print var_dump(json_decode($result,true));
我試圖JSON格式發送數據,但遺憾的是它並不能幫助。
編輯
應該顯示腳本的一段數據。
{"tabela":"\r\n\t\t\t\t<div class='provisionBox'>\r\n\t\t\t\t <img src = '\/img\/promotedIcon.png' class='promotionSign' \/>\r\n\t\t\t\t <div class='provisionBoxLeft'>\r\n\t\t\t\t \t<div class='provBoxRodzajIcon'> <img class='' src='\/_img\/product_icon\/konto_osobiste.png' alt='Konto osobiste' \r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttitle='Konto osobiste'><\/div>\r\n\t\t\t\t\t\t<div class='provBoxProductKind'>Rachunek osobisty \"Konto osobiste PLN\"<\/div>\r\n\t\t\t\t\t\t<div class='clear'><\/div>\r\n\t\t\t\t \t<div class='provBoxBankLogo'>
嗯,也許你應該首先檢查你實際從遠程服務器獲得的返回數據...... – CBroe
我粘貼了一個json數據樣本。 我嘗試了http://stackoverflow.com/questions/689185/json-decode-returns-null-after-webservice-call的提示,但不幸的是仍然無法正常工作。 – user3112825