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?