在 https 上使用 curl 获取 xml



所以我像这样登录网站:

    $ch = curl_init('https://emea2cps.adobeconnect.com/api/xml?action=login&login=username&password=password');
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
    curl_setopt($ch, CURLOPT_SSLVERSION,3);
    curl_exec($ch);
    $info= curl_getinfo($ch);
    echo 'passed' . $info['total_time'] . ' secconds ' . $info['url'] . '------ and http-code'. $info['http_code'];
    print curl_error($ch);

在我想通过此链接获取会议的XML之后 https://meet77842937.adobeconnect.com/api/xml?action=report-my-meetings

我尝试了以下代码:

$ch1 = curl_init('https://meet77842937.adobeconnect.com/api/xml?action=report-my-meetings');
    curl_setopt($ch1,CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch1, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
    curl_setopt($ch1, CURLOPT_SSLVERSION,3);
    curl_setopt($ch1,CURLOPT_RETURNTRANSFER,TRUE);
    $data = curl_exec($ch1);
    $info1= curl_getinfo($ch1);
    echo 'passed' . $info1['total_time'] . ' secconds ' . $info1['url'] . '------ and http-code'. $info1['http_code'];
    print curl_error($ch1);
    curl_close($ch1);
            curl_close($ch);
    $xml = new SimpleXMLElement($data);
    print_r($xml);

你能给我什么建议?

注意:当我在浏览器上输入此链接时,我可以看到 xml

结构:

<results>
    <status code="ok"></status>
    <my-meetings>
    <meeting sco-id="1282590819" type="meeting" icon="meeting" permission-id="host" active-participants="0">
    <meeting sco-id="1282620938" type="meeting" icon="meeting" permission-id="host" active-participants="0">
  </my-meetings>
 </results>

输出:像这样,例如:

sample1aksamaimeet77842937.adobeconnect.com/sample1/2014-02-28T06:15:00.000-08:002014-02-28T07:15:00.000-08:00false01:00:00.000sample2meet77842937.adobeconnect.com/sample2/2014-02-28T06:15:00.000-08:002014-02-28T07:15:00.000-08:00false01:00:00.000

尝试添加以下内容:

curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, FALSE);

也:

$data = curl_exec($ch1); // after this line
var_dump(htmlentities($data)); // add this one

以查看输出内容。它将为您提供调试的起点。

更新

加:

curl_setopt($ch, CURLOPT_COOKIEFILE, __DIR__.'/cookies');
curl_setopt($ch, CURLOPT_COOKIEJAR, __DIR__.'/cookies');
// repeat this for all $ch, $ch1, $ch2 and such where you need auth cookie available

存储登录信息并在其他请求中重复使用。您的错误显示您的第二个请求未经身份验证。所以我假设第一个为登录设置一个cookie,除非你需要继承第一个登录序列返回的变量。

删除 password 中的。您的密码有一个不应该存在的额外字符!

工作代码

// Login.
$ch = curl_init('https://emea2cps.adobeconnect.com/api/xml?action=login&login=username&password=password');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_COOKIEFILE, __DIR__.'/cookies');
curl_setopt($ch,CURLOPT_COOKIEJAR, __DIR__.'/cookies');
$data = curl_exec($ch);
var_dump($data);
curl_close($ch);
// Query.
$ch = curl_init('https://meet77842937.adobeconnect.com/api/xml?action=report-my-meetings');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_COOKIEFILE, __DIR__.'/cookies');
curl_setopt($ch,CURLOPT_COOKIEJAR, __DIR__.'/cookies');
$data = curl_exec($ch);
var_dump($data);
curl_close($ch);

阅读它。这已经足够清楚了。

相关内容

  • 没有找到相关文章

最新更新