PHP 服务器客户端错误

PHP server Client Error

我在 php 开发了一个简单的客户端和服务器,然后想到了这个

Client.php

<?php
// Create map with request parameters
$params = array ('name' => 'ASD', 'lastname' => 'SDF');

// Build Http query using params
$query = http_build_query ($params);

// Create Http context details
$contextData = array (
    'method' => 'POST',
    'header' => "Connection: close\r\n".
        "Content-Length: ".strlen($query)."\r\n",
    'content'=> $query );

// Create context resource for our request
$context = stream_context_create (array ( 'http' => $contextData ));

// Read page rendered as result of your POST request
$result =  file_get_contents (
    'http://localhost/phpserver/server.php',  // page url
    false,
    $context);

// Server response is now stored in $result variable so you can process it

服务器文件是:

Server.php

<?php

if( $_POST["name"] || $_POST["lastname"] )
{
    echo "Welcome: ". $_POST['sirname']. "<br />";
    echo "Your Email is: ". $_POST["lastname"]. "<br />";

}
?>

我收到一条错误消息

Notice: file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in C:\wamp\www\phpServer\client.php on line 22

我对php了解不多。只想在简单的服务器和客户端之间传递数据 (更好的无卷曲解决方案)

这是一个通知,不是错误。通过 POST 发送数据时,您应该设置内容类型 header。通知说你没有,它为你选择了最常见的。

查看 documentation 以获取有关如何明确设置内容类型的示例。

header 中有错误。 你可以使用这个
'header' => 'Content-type: application/x-www-form-urlencoded',