|
1 | 1 | <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 |
7 | 8 |
|
8 | 9 | # TIP: Use the $_SERVER Sugerglobal to get all the data your need from the Client's HTTP Request.
|
9 | 10 |
|
|
30 | 31 |
|
31 | 32 | #Body creation
|
32 | 33 |
|
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); |
35 | 36 |
|
36 | 37 | $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); |
46 | 39 | $httpResponse = $httpResponse->withBody($body);
|
47 | 40 |
|
48 |
| - |
49 |
| - |
50 | 41 | #Headers
|
51 | 42 |
|
52 | 43 | $httpResponse = $httpResponse->withAddedHeader('Date',date('D, d M Y H:i:s T'));
|
|
55 | 46 | $httpResponse = $httpResponse->withAddedHeader('Content-Length',strlen($httpResponse->getBody()->__toString()));
|
56 | 47 | $httpResponse = $httpResponse->withAddedHeader('Content_Type','application/json');
|
57 | 48 |
|
58 |
| - echo nl2br("HTTP/".$httpResponse->getProtocolVersion().' '.$httpResponse->getStatusCode().' '.$httpResponse->getReasonPhrase().PHP_EOL); |
| 49 | + echo "HTTP/".$httpResponse->getProtocolVersion().' '.$httpResponse->getStatusCode().' '.$httpResponse->getReasonPhrase().PHP_EOL; |
59 | 50 | foreach($httpResponse->headers as $name => $value)
|
60 | 51 | {
|
61 |
| - echo nl2br($name.': '.$value.PHP_EOL); |
| 52 | + echo $name.': '.$value.PHP_EOL; |
62 | 53 | }
|
63 | 54 |
|
64 |
| - echo nl2br($httpResponse->getBody()->__toString()); |
| 55 | + echo $httpResponse->getBody()->__toString(); |
65 | 56 |
|
66 | 57 |
|
67 | 58 |
|
68 | 59 | ?>
|
| 60 | +</pre> |
69 | 61 | </body>
|
70 | 62 | </html>
|
0 commit comments