File_get_contents Unable to request a workaround for HTTPS connections PHP turns on Curl

Source: Internet
Author: User
Tags http post vars

File_get_contents cannot request a workaround for HTTPS connections

Method 1:

PHP.ini The default configuration, the link to the HTTPS is read with file_get_contents, the error is as follows:

Warning:fopen () [function.fopen]: Unable to find the wrapper "https"-do you forget to enable it when you configured PH P?

The solution has 3:
1.windows PHP, only need to php.ini in front of the Extension=php_openssl.dll , delete, restart the service can be.
2.linux PHP, you must install the OpenSSL module, installed in the future can be accessed.
3. If the server you can not modify the configuration, then use the Curl function to replace the file_get_contents function, of course, is not a simple replacement ah. There is also a corresponding parameter configuration to use the Curl function properly.

The Curl function is encapsulated as follows:

[PHP]View Plaincopyprint?
  1. function Http_request ($url,$timeout =30,$header =Array ()) {
  2. if (!function_exists (' Curl_init ')) {
  3. throw New Exception (' Server not install curl ');
  4. }
  5. $ch = Curl_init ();
  6. curl_setopt ($ch, Curlopt_returntransfer, true);
  7. curl_setopt ($ch, Curlopt_header, true);
  8. curl_setopt ($ch, Curlopt_url, $url);
  9. curl_setopt ($ch, curlopt_timeout, $timeout);
  10. if (! Empty ($header)) {
  11. curl_setopt ($ch, Curlopt_httpheader, $header);
  12. }
  13. $data = curl_exec ($ch);
  14. List ($header, $data) = explode ("\r\n\r\n", $data);
  15. $http _code = Curl_getinfo ($ch, Curlinfo_http_code);
  16. if ($http _code = = 301 | | $http _code = = 302) {  
  17. $matches = Array ();
  18. Preg_match ('/location: (. *?)  \n/', $header, $matches);
  19. $url = Trim (array_pop ($matches));
  20. curl_setopt ($ch, Curlopt_url, $url);
  21. curl_setopt ($ch, Curlopt_header, false);
  22. $data = curl_exec ($ch);
  23. }
  24. if ($data = = False) {
  25. Curl_close ($ch);
  26. }
  27. @curl_close ($ch);
  28. return $data;
  29. }

php to turn on Curl

To open the PHP Curl Library

1). Remove the Windows/php.ini file; Extension=php_curl.dll Front; /* with Echo phpinfo (); View PHP.ini's Path */

2). Copy the Php5/libeay32.dll,ssleay32.dll to the system directory windows/

3). Restart Apache

Configure PHP to support curl

Curl is a file transfer tool that works with URL syntax in the command line mode. It supports many protocols: FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE, and LDAP. Curl also supports HTTPS authentication, HTTP POST method, HTTP put method, FTP upload, Kerberos authentication, HTTP upload, proxy server, cookies, username/password Authentication, download file breakpoint continuation, upload file breakpoint continuation, HTTP Proxy service (proxy tunneling), even it supports IPV6, SOCKS5 proxy server, uploading files via HTTP proxy server to FTP server and so on, the function is very powerful. Windows operating system under the network ant, the Internet Express (FlashGet) function it can do. To be exact, curl supports file uploads and downloads, so it's a comprehensive transfer tool, but traditionally, users are accustomed to calling curl a download tool.

Configuration method:

1, copy the PHP directory of Libeay32.dll and ssleay32.dll two files to system32 directory.

2, modify PHP.ini: Configure the Extension_dir, remove extension = Php_curl.dll front of the semicolon.

---------------------------

Installation of extended Php_curl.dll under PHP

---------------------------

The Php_curl.dll is already built in, and in the EXT directory, this DLL is used to support SSL and zlib.

Find the Extension=php_curl.dll in php.ini and remove the previous comment.

Set Extension_dir=c:phpext, refresh php page times wrong, said to find module Php_curl.dll.

Copy Php_curl.dll to Windowssystem32, or the same mistake.

On the internet to find a bit, you need to:

Libeay32.dll, Ssleay32.dll, Php5ts.dll, Php_curl.dll

are copied to the System32 directory, restart IIS.

File_get_contents Unable to request a workaround for HTTPS connections PHP turns on Curl

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.