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