Mercurial > hg > Members > nobuyasu > konoha
changeset 14:bc647a5f0421 draft
modify HttpRequest.k
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 29 May 2012 00:22:51 +0900 |
parents | 0335cdd081d0 |
children | 44e3247ed7c1 |
files | http/HttpRequest.k http/httpRequestTest.k http/url.k |
diffstat | 3 files changed, 10 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/http/HttpRequest.k Mon May 28 23:56:15 2012 +0900 +++ b/http/HttpRequest.k Tue May 29 00:22:51 2012 +0900 @@ -35,7 +35,7 @@ } void printRequestProperty() { - foreach (String key in property.keys()) + for (String key : property.keys()) OUT << key +": " + property[key] << EOL; }
--- a/http/httpRequestTest.k Mon May 28 23:56:15 2012 +0900 +++ b/http/httpRequestTest.k Tue May 29 00:22:51 2012 +0900 @@ -1,19 +1,18 @@ include "HttpRequest.k" - - -void printResponse(InputStream in) { - print("print Response"); +String getResponse(InputStream in) { + String str = ""; while ( !in.isClosed() ) { String ret = in.readLine(); - OUT << ret << EOL; + str = str + ret + EOL; } + return str; } void main(String[] args) { - URL url = new URL("http://dimolto.cr.ie.u-ryukyu.ac.jp/~aotokage/post.php"); + URL url = new URL("http://dimolto.cr.ie.u-ryukyu.ac.jp/~aotokage/cache.php"); HttpRequest r = new HttpRequest(url); r.openConnection(); r.setMethod("POST"); @@ -22,13 +21,13 @@ r.setRequestProperty("Cache-Control","no-cache"); r.setRequestProperty("Accept-Language","en"); r.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - r.setBody("sub=AAAAAAAA&txt=BBB"); + r.setBody("cacheA=AAAAAAAA&cacheB=BBB"); r.writeRequest(); - r.printRequest(); - +// r.printRequest(); InputStream in = r.getInputStream(); - printResponse(in); + String ret = getResponse(in); + OUT <<< ret.split("\n\n")[1] <<< EOL; r.close(); } \ No newline at end of file