Phalanger
Phalanger copied to clipboard
HTTPS wrapper not available?
Hi there,
Trying to use file_get_contents() for an https:// url however I'm getting
Notice: file_get_contents(): Unable to find the wrapper 'https' - did you forget to enable it when you configured PHP?
Normally (without Phalanger), enabling the openssl module would provide this wrapper, however adding the php_openssl.mng assembly does not resolve this.
Even with php_openssl.mng added (and confirmed that it's loaded through a call to phpinfo()), a check of stream_get_wrappers() only returns 'ftp' and 'http' (twice, oddly)
Is there something else I need to do to enable the https stream wrapper in Phalanger?
Cheers, Eion
It's not just as simple as adding 'https' as another case in the scheme check in the PHP.Core.StreamWrapper.GetWrapperInternal method (StreamWrappers.cs:676), is it?
+1
I'm also struggeling with this, did you find a solution?
Curl turns out to work out of the box with SSL, curl is a native phalanger extension.
First you need to add curl in your app.config
<phpNet>
<classLibrary>
<add assembly="PhpNetClassLibrary, Version=3.0.0.0, Culture=neutral, PublicKeyToken=4af37afe3cde05fb" section="bcl" />
<add assembly="PhpNetCurl, Version=3.0.0.0, Culture=neutral, PublicKeyToken=2771987119c16a03" section="curl" />
</classLibrary>
</phpNet>
Also you need to include PhpNetCurl.dll in your distribution. Then you can execute requests using php curl functions.
$url = "https://some.url.com/foo/bar" . $path;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1); //0 for a get request
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$response = curl_exec($ch);
print "curl response is:" . $response;
curl_close($ch);
Works for me, good luck!
Thanks, but I'm struggeling to get this to work. I don't get any result in the output.
Heres the code I have so far:
function curl_post($url, $postvars) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 0); //0 for a get request
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$response = curl_exec($ch);
print "curl response is:" . $response;
curl_close($ch);
}
$id = "ide";
$class = "openingTitle";
$url = "https://external.page.com/subdir/";
$postvars = "ClassAddr=$class&id=$id";
echo curl_post($url, $postvars);
And heres the raw-data I want to pull:
<div id="ide">
<div>
<div class="openingTitle"><a href="./opening;jsessionid=E2A19018E967B4771224A9FA515AFBC0?0-1.ILinkListener-content-contentPanel-openings~view~container-openings~view-0-details"><span style="font-weight:bold;">fagarbeider</span></a></div>
<div class="openingIngress"><p>Avdeling teknisk drift har ledig stilling som fagarbeider vann/avløp.<br/>Fast, 100 %, ledig snarest.</p></div>
<div class="openingDetail"><i>Utlyst: <span>28.01.2015</span></i></div>
<div class="openingDetail"><i>Søknadsfrist: <span style="color:red">01.03.2015</span></i></div>
<div class="openingDetail"><i>Selskap: <span>Randaberg kommune</span></i></div>
<div class="openingDetail"><i>Stillingstype: <span>Fast ansatt</span></i></div>
<div class="openingDetail"><i>Lokasjon: <span>Avd. teknisk drift</span></i></div>
<div class="openingDetail">
</div>
</div>