2016-04-09 15 views
0

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

は私のコードです:

<?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(); 

私が代わりに私は "X" を取得、出力 "XXXXX" を期待しています。

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

私は "カール-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 

を取得。

EDIT これらの行をファイルの末尾に追加すると、応答は正しくなります。

$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 

私は理由を理解できません.....?

答えて

1

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

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

関連する問題