PHP's question about passing parameters to a local file by the file_get_contens function

Source: Internet
Author: User
PHP questions about passing parameters from the file_get_contens function to a local file

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 code. One is the interface. php file.

I will write the above source code on this file. Use file_get_contents to POST data to the interface. php file. Result: No data is received by interface. php.

I don't know where the error occurred. Please enlighten me !!!!


Reply to discussion (solution)

Protocol Type required
Echo file_get_contents ("http: // localhost/interface. php", true, $ context );

In addition
The header must 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 ",

It takes effect only when \ r \ n is in double quotation marks.

In addition
The header must 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 is to say, it will definitely not work without HTTP !!!

This parameter is just curl get.

Reference the reply on the third floor:
In addition
The header must 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, but it is a file system function. You can't do it if you want monkeys to fly. Sun Wukong turned his muscles and muscles through the mouth of the old Bodhi ancestor.

Why does file_get_contents get the complete json content, but it is incomplete to get the json content using 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.