# HG changeset patch # User Nobuyasu Oshiro # Date 1337258259 -32400 # Node ID f85060c918172db900b159d3a10d48603e346302 # Parent 68307ce6839d83c215f7e60a1cd58e06b3e26a28 add requet.k diff -r 68307ce6839d -r f85060c91817 http/request.k --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/http/request.k Thu May 17 21:37:39 2012 +0900 @@ -0,0 +1,86 @@ +using konoha.io.*; +using konoha.socket.*; + + +class HttpRequest() +{ + int port; + String method, uri; + String host, connection, charset, cacheControl, language; + Socket sock; + InputStream in; + OutputStream out; + HttpRequest() { + port = 80; + method = "GET"; + uri = "index.html"; + host = "google.co.jp"; + host = "google.co.jp"; + charset = "UTF-8"; + connection = "close"; + cacheControl = "no-cache"; + language = "en"; + } + + void setHost(String _host) { + host = _host; + } + + void connectToHost() { + sock = new Socket(host, port); + in = new sock.getInputStream(); + out = new sock.getOutputStream(); + } + + void sendRequest() { + out <<< method + "/" + uri + "HTTP/1.1" <<< EOL; + out <<< "HOST: " + host <<< EOL; + out <<< "Connection: " + connection <<< EOL; + out <<< "Accept-Charset: " + charset <<< EOL; + out <<< "Cache-Control: " + cacheControl <<< EOL; + out <<< "Accept-Language: " + language <<< EOL; + out <<< "" <<< EOL; + } + + void printResponse() { + while ( !in.isClosed() ) { + String ret = in.readLine(); + print ret; + } + } + + +} + + + +void main(String[] args) +{ + int port = 80; // port number of http protocol + String host = "dimolto.cr.ie.u-ryukyu.ac.jp"; + + Socket sock = new Socket(host, port); + InputStream in = sock.getInputStream(); + OutputStream out = sock.getOutputStream(); + + out <<< "GET /index.html HTTP/1.1" <<< EOL; + out <<< "Host: dimolto.cr.ie.u-ryukyu.ac.jp" <<< EOL; + out <<< "Connection: close" <<< EOL; + out <<< "Accept-Charset: UTF-8" <<< EOL; + out <<< "Cache-Control: no-cache" <<< EOL; + out <<< "Accept-Language: en" <<< EOL; + out <<< "" <<< EOL; + out.flush(); + while ( !in.isClosed() ) { + String ret = in.readLine(); + print ret; + } + in.Close(); + out.close(); + + + HttpRequest h = new HttpRequest(); + + + +} \ No newline at end of file