Created
October 6, 2016 16:26
-
-
Save am4dr/fefe52ecc12abe324a212202df40ee2a to your computer and use it in GitHub Desktop.
with Java Socket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| new Socket('example.com', 80).withStreams { is, os -> | |
| def req = 'GET / HTTP/1.1\r\nHost: example.com\r\n\r\n' | |
| println "[[$req]]" | |
| os << req.getBytes('utf-8') | |
| System.out << is // blocking | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [[GET / HTTP/1.1 | |
| Host: example.com | |
| ]] | |
| HTTP/1.1 200 OK | |
| Cache-Control: max-age=604800 | |
| Content-Type: text/html | |
| Date: Thu, 06 Oct 2016 16:19:56 GMT | |
| Etag: "359670651+gzip+ident" | |
| Expires: Thu, 13 Oct 2016 16:19:56 GMT | |
| Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT | |
| Server: ECS (pae/3796) | |
| Vary: Accept-Encoding | |
| X-Cache: HIT | |
| x-ec-custom-error: 1 | |
| Content-Length: 1270 | |
| <!doctype html> | |
| <html> | |
| <head> | |
| <title>Example Domain</title> | |
| <meta charset="utf-8" /> | |
| <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | |
| <style type="text/css"> | |
| body { | |
| background-color: #f0f0f2; | |
| margin: 0; | |
| padding: 0; | |
| font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; | |
| } | |
| div { | |
| width: 600px; | |
| margin: 5em auto; | |
| padding: 50px; | |
| background-color: #fff; | |
| border-radius: 1em; | |
| } | |
| a:link, a:visited { | |
| color: #38488f; | |
| text-decoration: none; | |
| } | |
| @media (max-width: 700px) { | |
| body { | |
| background-color: #fff; | |
| } | |
| div { | |
| width: auto; | |
| margin: 0 auto; | |
| border-radius: 0; | |
| padding: 1em; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div> | |
| <h1>Example Domain</h1> | |
| <p>This domain is established to be used for illustrative examples in documents. You may use this | |
| domain in examples without prior coordination or asking for permission.</p> | |
| <p><a href="http://www.iana.org/domains/example">More information...</a></p> | |
| </div> | |
| </body> | |
| </html> | |
| Result: java.io.PrintStream@75067774 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment