2015-03-19 45 views
2

我一直在嘗試使用AIDA disambiguation service。他們發佈的cURL示例在終端上運行良好。但是,當我嘗試通過PHP實現它時,我立即得到一個空的響應。最重要的是,我試圖基本上從Javascript訪問這個資源,但據我所知,通過PHP是從另一個域訪問資源的最佳途徑。cURL通過終端工作,不通過PHP

我的PHP代碼:

<?php 
//set POST variables 
$url = $_POST['url']; 
unset($_POST['url']); 

$curl = curl_init(); 

curl_setopt($curl,CURLOPT_URL,$url); 
curl_setopt($curl,CURLOPT_POST,count($_POST)); 
curl_setopt($curl,CURLOPT_HTTPHEADER,array('Expect:')); 
curl_setopt($curl,CURLOPT_POSTFIELDS,$_POST); 
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); 

$a = curl_exec($curl); 
error_log('Status: '.var_dump(curl_getinfo($curl))); 
curl_close($curl); 
?> 

的curl_getinfo:

array(26) { 
    ["url"]=> 
    string(56) "https://gate.d5.mpi-inf.mpg.de/aida/service/disambiguate" 
    ["content_type"]=> 
    NULL 
    ["http_code"]=> 
    int(0) 
    ["header_size"]=> 
    int(0) 
    ["request_size"]=> 
    int(0) 
    ["filetime"]=> 
    int(-1) 
    ["ssl_verify_result"]=> 
    int(0) 
    ["redirect_count"]=> 
    int(0) 
    ["total_time"]=> 
    float(0.125) 
    ["namelookup_time"]=> 
    float(0) 
    ["connect_time"]=> 
    float(0.063) 
    ["pretransfer_time"]=> 
    float(0) 
    ["size_upload"]=> 
    float(0) 
    ["size_download"]=> 
    float(0) 
    ["speed_download"]=> 
    float(0) 
    ["speed_upload"]=> 
    float(0) 
    ["download_content_length"]=> 
    float(-1) 
    ["upload_content_length"]=> 
    float(-1) 
    ["starttransfer_time"]=> 
    float(0) 
    ["redirect_time"]=> 
    float(0) 
    ["redirect_url"]=> 
    string(0) "" 
    ["primary_ip"]=> 
    string(12) "139.19.87.30" 
    ["certinfo"]=> 
    array(0) { 
    } 

$a就是空的。 $url設置正確。唯一的其他變量,text,似乎也正確設置。任何人都知道這裏可能會出錯嗎?

回答

1

類似的東西,我從AIDA網絡服務的答案。 在$結果中發佈您想要消除歧義的文字。

<?php 
$url = "https://gate.d5.mpi-inf.mpg.de/aida/service/disambiguate"; 

$curl = curl_init(); 

curl_setopt($curl,CURLOPT_URL,$url); 
curl_setopt($curl, CURLOPT_POST, true); // tell curl you want to post something 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($curl, CURLOPT_POSTFIELDS, "text='".$result."'"); 
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); 

$a = curl_exec($curl); 
curl_close($curl); 
var_dump($a); 

?> 

我希望這將幫助你