PHP four ways to invoke a way URL

Source: Internet
Author: User
PHP four ways to invoke a remote URL
1. Get content with file_get_contents in get mode
Example:

2. Open the URL with fopen and get the content in Get mode
Example:

3, using the File_get_contents function, the Post method to obtain the URL
$data = Array (' Test ' = ' hellword '); $data = Http_build_query ($data); $opts = Array ('  http ' = = Array (  ' method ' = ' + ' POST ',  ' header ' = ') ' content-type:application/ x-www-form-urlencoded\r\n ".     " Content-length: ". Strlen ($data). "\ r \ n",  ' content ' = $data  ),); $context = Stream_context_create ($opts); $html = File_get_contents ($url, False, $context);

4, using the Curl Library, before using the Curl Library, you need to confirm that there is an open Curl extension
$ch = Curl_init (); $timeout = 5; curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_connecttimeout, $timeout); $file _contents = curl_exec ($ch); Curl_close ($ch); echo $file _contents;

  • Related Article

    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.