Problems getting XML content via https using SimpleXML and PHP [duplicate]

巧了我就是萌 提交于 2019-12-31 07:36:31

问题


Possible Duplicate:
How to enable HTTPS stream wrappers

I'm using simple XML to get content from an API. Usually I have no problems but now the URL is HTTPS it doesn't seem to work. Is there anyway around this?

Example XML (url):

<?xml version="1.0"?>
<calendars>
  <calendar accommodation_id="1049165">
    <day date="2012-08-09" vacancy="false" minimum_nights="7" arrival_day="true"/>
    <day date="2012-08-10" vacancy="false" minimum_nights="3" arrival_day="true"/>
    <day date="2012-08-11" vacancy="false" minimum_nights="3" arrival_day="true"/>
    <!-- ... -->
    <day date="2014-01-31" vacancy="true" minimum_nights="3" arrival_day="true"/>
  </calendar>
</calendars>

Example code:

$xml2 = file_get_contents('');
$availability = new SimpleXMLElement($xml2);

回答1:


You are using the XML API of the www.casapilot.com website.

The API is via HTTPS, one example URI is:

https://www.casapilot.com/api/1/accommodations/calendar.xml?auth_token=hyXHjP8QdrRuX8q3FsbC&id=1049165

For HTTPs to work, PHP needs the openssl extension. The information is given on the related Stream Wrapper Page:

Note: HTTPS is only supported when the openssl extension is enabled.

The openssl extension is then used for all HTTPS "files" transparently with the stream-wrapper for all URIs starting with https://.

See as well the duplicate question:

  • How to enable HTTPS stream wrappers


来源:https://stackoverflow.com/questions/11883575/problems-getting-xml-content-via-https-using-simplexml-and-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!