cURL通过终端工作,而不是通过PHP

时间:2015-03-19 12:16:20

标签: php curl

我一直在尝试使用AIDA disambiguation service。他们发布的cURL示例通过终端正常工作。但是,当我尝试通过PHP实现它时,我立即得到一个空响应。最重要的是,我试图从Javascript中尝试访问此资源,但据我所知,通过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 个答案:

答案 0 :(得分:1)

有类似的东西,我得到了AIDA网络服务的答案。 在$ result中发布您想要消除歧义的文本。

<?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);

?>

我希望能帮到你

相关问题