Skip to content

Commit cd723f9

Browse files
committed
Made the display of the http response work.
1 parent 31869fa commit cd723f9

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

public/index.php

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<html>
2-
<head>
3-
<title>PHP Test</title>
4-
</head>
5-
<body>
6-
<?php
2+
<head>
3+
<title>PHP Test</title>
4+
</head>
5+
<body>
6+
<pre>
7+
<?php
78

89
# TIP: Use the $_SERVER Sugerglobal to get all the data your need from the Client's HTTP Request.
910

@@ -30,23 +31,13 @@
3031

3132
#Body creation
3233

33-
$id = "\t".'"@id":'.$httpRequest->getRequestTarget().'",';
34-
$timeSent = "\t".'"timeSent":"'.time().'"';
34+
$bodyArray = array('@id'=> $httpRequest->getRequestTarget(), 'to' => 'Pillr', 'subject'=>'Hello Pillr','message'=>'Here is my submission','from'=>'Felix Dube','timesent'=>time());
35+
$bodyJson = json_encode($bodyArray,JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);
3536

3637
$body = new Stream;
37-
$body->write('{');
38-
$body->write($id);
39-
$body->write("\t".'"to": "Pillr",');
40-
$body->write("\t".'"subject": "Hello Pillr",');
41-
$body->write("\t".'"message": "Here is my submission.",');
42-
$body->write("\t".'"from": "Felix Dube",');
43-
$body->write($timeSent);
44-
$body->write("}");
45-
38+
$body->write($bodyJson);
4639
$httpResponse = $httpResponse->withBody($body);
4740

48-
49-
5041
#Headers
5142

5243
$httpResponse = $httpResponse->withAddedHeader('Date',date('D, d M Y H:i:s T'));
@@ -55,16 +46,17 @@
5546
$httpResponse = $httpResponse->withAddedHeader('Content-Length',strlen($httpResponse->getBody()->__toString()));
5647
$httpResponse = $httpResponse->withAddedHeader('Content_Type','application/json');
5748

58-
echo nl2br("HTTP/".$httpResponse->getProtocolVersion().' '.$httpResponse->getStatusCode().' '.$httpResponse->getReasonPhrase().PHP_EOL);
49+
echo "HTTP/".$httpResponse->getProtocolVersion().' '.$httpResponse->getStatusCode().' '.$httpResponse->getReasonPhrase().PHP_EOL;
5950
foreach($httpResponse->headers as $name => $value)
6051
{
61-
echo nl2br($name.': '.$value.PHP_EOL);
52+
echo $name.': '.$value.PHP_EOL;
6253
}
6354

64-
echo nl2br($httpResponse->getBody()->__toString());
55+
echo $httpResponse->getBody()->__toString();
6556

6657

6758

6859
?>
60+
</pre>
6961
</body>
7062
</html>

0 commit comments

Comments
 (0)