1

我正在努力完成与 cloudant 的连接。

以下是为 php 使用 sag 库:

<?php
header('Content-Type: text/html; charset=utf-8');
require_once('../../src/Sag.php');

//this credentials are from API key
$uName="";
$pName="";

$sag = new Sag('user.cloudant.com');
$sag->login($uName, $pName);
$sag->setDatabase('test');


try {
$result = $sag->get('/test/_design/wordsP/_view/errores');
echo ($result);
}
catch(Exception $e) {
error_log("Something's wrong");
var_dump($e);
}
?>

但是我没有得到预期的结果()。如果仅在 url 栏中使用,该视图确实有效。

回应是:

object(SagException)#3(6){
[
    "message:protected"
]=>string(50)"Sag Error: cURL error #7: couldn't connect to host"[
    "string:private"
]=>string(0)""[
    "code:protected"
]=>int(0)[
    "file:protected"
]=>string(73)"/home2/.../public_html/clant/src/httpAdapters/SagCURLHTTPAdapter.php"[
    "line:protected"
]=>int(134)[
    "trace:private"
]=>array(3){ .............

有什么我没有在 php 脚本中正确使用的东西吗?(删除了当前密码+用户名以及帐户,但它们在那里)。

4

1 回答 1

0

curl 错误 7 表示您无法连接到主机或代理:

CURLE_COULDNT_CONNECT (7)

无法连接()到主机或代理。

来源:http ://curl.haxx.se/libcurl/c/libcurl-errors.html

如果您的浏览器使用代理,则当您从浏览器连接到 URL 时,您还需要配置 sag 以使用该代理。

另外,当您说您在代码示例中替换了帐户时,您的意思是用您的实际用户名替换user了吗?$sag = new Sag('user.cloudant.com');如果没有,您将需要使用您的实际用户名。

于 2014-10-08T06:07:23.947 回答