PHP about the File_get_contens function to the local file parameters of the problem

Source: Internet
Author: User
PHP about the File_get_contens function to the local file parameters of the problem

The source code is as follows:
$str _query = "Userid=admin&gameid=game1&serverid=server1";


$context = stream_context_create (Array (
' http ' = = Array (
' Method ' = ' POST ',
' Timeout ' = 10,
' Header ' = ' user-agent:mozilla/5.0 ' (Windows; U Windows NT 5.1; En-US) applewebkit/534.13 (khtml, like Gecko) chrome/9.0.597.98 safari/534.13\r\ncontent-type:application/ X-www-form-urlencoded\r\n ',
' Content ' = $str _query
)
));

Echo file_get_contents ("interface.php", true, $context);

?>

There are two files on the local aparche server. One is to put the above source files. One is the interface.php file.

I write the source code as above on this document. Post data to the interface.php file with file_get_contents. The result interface.php no data received.

I don't know where it went wrong. Ask Master Enlighten!!!!


Reply to discussion (solution)

Requires a protocol type
Echo file_get_contents ("http://localhost/interface.php", true, $context);

In addition to the parameter array
Header items to be written
' Header ' = ' + ' user-agent:mozilla/5.0 (Windows; U Windows NT 5.1; En-US) applewebkit/534.13 (khtml, like Gecko) chrome/9.0.597.98 safari/534.13\r\ncontent-type:application/ X-www-form-urlencoded\r\n ",

Only in double quotes \ r \ n will take effect

In addition to the parameter array
Header items to be written
' Header ' = ' + ' user-agent:mozilla/5.0 (Windows; U Windows NT 5.1; En-US) applewebkit/534.13 (khtml, like Gecko) chrome/9.0.597.98 safari/534.13\r\ncontent-type:application/x-www-......



Oh? That means there is no HTTP so it must not be!!!

This parameter is just curl get.

Reference to the 3 floor of the reply:
In addition to the parameter array
Header items to be written
' Header ' = ' + ' user-agent:mozilla/5.0 (Windows; U Windows NT 5.1; En-US) applewebkit/534.13 (khtml, like Gecko) chrome/9.0.597.98 Safari/534.13\r\ncontent-type:app ...

There is no Internet protocol, just a file system function. If you want a monkey to fly, it can't be done. The Monkey King is just using the Bodhi old man's formula to turn the somersault.

Why would file_get_contents get the full JSON content, while using curl to get an incomplete JSON content?

  • 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.