douguan1887 2014-02-25 15:45
浏览 31
已采纳

在https上使用curl获取xml

So I made a login to site like this:

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

After I want to fetch XML of my meetings by this link https://meet77842937.adobeconnect.com/api/xml?action=report-my-meetings

I tried the following code:

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

What can you advise me?

Note: i can see xml when i input this link on browser

Structure:

<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>

Output: like this for ex:

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
  • 写回答

1条回答 默认 最新

  • dspym82000 2014-02-25 15:56
    关注

    Try adding this:

    curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, FALSE);
    

    Also:

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

    to see what's the output. It'll give you a starting point to debug.

    UPDATE

    Add:

    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
    

    to store the login information and reuse it in other requests. Your error shows your second request goes unauthenticated. So I assume first one sets a cookie for login unless you need to carry over a variable returned by the first login sequence.

    AND remove the \ in password\. Your password has an extra character that should not be there!

    Working code:

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

    Read it. It's clear enough.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!