0

更新:我发现这个问题与我的托管设置有关。该代码由 Media Temple 托管在 DV 服务器上,但是我将完全相同的代码放在 GS Media Temple 服务器上,它按预期工作。那么关于两者之间可能有什么不同的任何想法?


想知道是否有人可以解释为什么我不能让这个 API 调用工作。只是试图获取表单输入数据。如果我将 JSON 的 URL 粘贴到浏览器中,它会按您的预期显示,但在此调用中我无法获得任何服务器响应。

<?php


$api_uri_1 = "https://eastbankads.wufoo.com/api/v3/forms/z1qh9i4b1qg5qa6/entries.json";

function wufoo_api($api_uri) {
  $curl = curl_init($api_uri);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_USERPWD, 'MY-API-KEY:password');
  curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($curl, CURLOPT_USERAGENT, 'Wufoo Sample Code');
  $response = curl_exec($curl);
  $resultStatus = curl_getinfo($curl);

  if ($resultStatus['http_code'] == 200) {
    $results = json_decode($response, true);
    return $results;
  } else {
    $results = 'Call Failed '.print_r($resultStatus);
    return $results;
  }
}

$result1 = wufoo_api($api_uri_1);

?>

我已经检查并仔细检查了我的 API 密钥。这是我的测试页面的链接以及代码给出的输出:

http://resources.worldoftile.net/wufoo-perfect-project-entries/

或者,这是该页面上的输出:

Array ( 
  [url] => https://eastbankads.wufoo.com/api/v3/forms/z1qh9i4b1qg5qa6/entries.json 
  [content_type] => 
  [http_code] => 0 
  [header_size] => 0 
  [request_size] => 132 
  [filetime] => -1 
  [ssl_verify_result] => 0 
  [redirect_count] => 0 
  [total_time] => 0.068676 
  [namelookup_time] => 2.2E-5 
  [connect_time] => 0.009197 
  [pretransfer_time] => 0 
  [size_upload] => 0 
  [size_download] => 0 
  [speed_download] => 0 
  [speed_upload] => 0 
  [download_content_length] => -1 
  [upload_content_length] => 0 
  [starttransfer_time] => 0 
  [redirect_time] => 0.068764 
  [certinfo] => Array ( ) 
  [primary_ip] => 75.98.93.66 
  [redirect_url] => 
)
4

1 回答 1

-1

删除以下行将解决此问题。

curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

于 2016-11-13T15:37:19.743 回答