0

Windows 7 システムで Slim を実行しようとしています。これまでのところ、Composer ですべてをインストールしましたが、非常に単純なプログラムを実行すると、出力が意図したとおりになりません。

以下は私のコードです:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

use Slim\App;
use Slim\Http\Request;
use Slim\Http\Response;

require '../vendor/autoload.php';

$app = new App;

$app->get('/', function (Request $in, Response $out, $args) {
 return $out->write("xxxxx");
});

$app->run();

出力「xxxxx」を期待していますが、代わりに「x」が表示されます。

これは、どこかで 4 文字を失うことを意味します。PHP 5.5.12 の実行 エンコーディングは UTF-8 (BOM ではない)

「curl -v http://localhost:8080/」を実行すると

私は得る

D:\wamp\www\slim_test\src\public>curl -v http://localhost:8080/
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Host: localhost:8080
< Connection: close
< X-Powered-By: PHP/5.5.12
< Content-Type: text/html; charset=UTF-8
< Content-Length: 5
<

x* Closing connection 0

よろしくお願いします。

編集 これらのコード行をファイルの最後に追加すると、応答は正しくなります。

$response = $app->run(true); //Silent mode, wont send the response
$response = $response->withoutHeader("Content-Length"); //Remove the Content-Length

$app->respond($response); //Now we send the response

なぜだか分からない……?

4

1 に答える 1

1

非常にばかげた間違いを見つけたので、この問題は解決されました。

<?phpタグの前に 2 つの空白がありました。

于 2016-05-06T09:43:29.227 に答える