我在一個URL上擁有CMS,並且至少有68個屬性網站在不同的域中運行該CMS。CURL無法抓取HTML內容
我試圖從屬性的網站在CMS一個模式來顯示一個搶的形式(允許其他屬性來查看錶單,以決定是否要包括它。)
在引導頁面上,我有這樣的腳本:
(function() {
$(document).on('click', '.btnModal', function(e){
e.preventDefault();
var formID = $(this).data('form');
$.ajax({
url: "<?= site_url('staffer/get_form_modal'); ?>",
type: "POST",
data: { fid: formID },
success: function(msg){
$('#modal-body').html(msg);
$('#myModal').modal('show');
} // end success
});
});
})(); // end self-invoking anonymous function
在控制器方面,這是捲曲代碼:
public function get_form_modal($fid = null){
if(!$fid){ $fid = $this->input->post('fid'); }
$form = $this->istaff_m->get_modal_form($fid);
$html = '';
$url = $this->boilerplate['propertyInfo'][0]['istaffURL'] . 'staff/' . $form[0]->URL;
// $url echos http://istaff.edrtest.com/staff/res_lr
$url = (string) trim(strip_tags($url));
$url = str_replace('&', '&', $url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result= curl_exec ($ch);
if($result === false){
echo "Curl error: " . @curl_error($ch);
} // end if
curl_close ($ch);
echo $result;
} // end get_form_modal function
/*-----------------------------------------------------*/
的模式與它的頭和一個空的身體彈出。沒有錯誤信息...只是空白。
Firebug顯示發佈的表單ID和空的響應 - 再次沒有錯誤消息。
任何幫助表示讚賞!
UPDATE:在服務器上使用SSH,我跑了 '捲曲-I' http://istaff.edrtest.com/staff/res_lr'和得到以下內容:
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 16 Dec 2013 16:15:56 GMT
Content-Type: text/html
Connection: keep-alive
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Refresh: 0;url=http://istaff.edrtest.com/user/log_in
Set-Cookie: PHPSESSID=kbc674bc07nn4aeh2k5rsur685; path=/
X-Powered-By: PleskLin
嘗試添加'curl_setopt($ ch,CURLOPT_VERBOSE,true);'。看看能否幫助你進行調試。 – Abs
沒有變化...仍然沒有錯誤信息。 – jgravois
通過直接調用方法來測試您的CURL請求是否在沒有AJAX的情況下工作。 – Abs