【问题标题】:PHP server Client ErrorPHP服务器客户端错误
【发布时间】:2016-03-16 09:44:06
【问题描述】:

我正在用 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 />";

}
?>

我说错了

注意:file_get_contents():假设内容类型未指定 应用程序/x-www-form-urlencoded 在 C:\wamp\www\phpServer\client.php 在第 22 行

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

【问题讨论】:

    标签: php post server client


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 谢谢你在文档上找到了
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多