PHP using file_get_contents to send HTTP request steps in detail

Source: Internet
Author: User
This time for everyone to bring PHP using file_get_contents send HTTP request steps in detail, PHP use file_get_contents send HTTP request Note What, here is the actual case, together to see.

Server-side simulation Post/get and other requests, using curl is easy to do, so what if you don't use the Curl library?

$data = Array (  ' test ' = ' bar ',  ' baz ' = ' boom ',  ' site ' = ' www.nimip.com ',  ' name ' = ' = ') Nimip.com '); $data = Http_build_query ($data);//$postdata = Http_build_query ($data); $options = Array (  ' http ' = = Array (    ' method ' = ' + ' POST ',    ' header ' = ' content-type:application/x-www-form-urlencoded ',    ' Content ' = ' $data    ' timeout ' + 60//timeout (in s))  ; $url = "http://www.testweb.com"; $context = Stream_ Context_create ($options); $result = File_get_contents ($url, False, $context); Echo $result;

Where the http://www.testweb.com code is:

$data = $_post;print_r ($data);

stream_context_create() Role: Create and return a text stream and apply a variety of options that can be used fopen() , file_get_contents() such as the time-out setting of the process, the proxy server, the request method, and the special procedure for setting the header information.

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

YII2 Framework data validation using detailed

How to use the PDO transaction in PHP

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.