I create DefaultHttpClient Class and set url, create Http Get Message.
String url = "http://www.yahoo.co.jp"; HttpClient hc = new DefaultHttpClient(); HttpGet get = new HttpGet(url);I do http Get execute. and receive http response.
HttpResponse res; res = hc.execute(get);If response is 200 OK, I get http content.
if (res.getStatusLine().getStatusCode() == 200) { //It is ok. InputStream input = res.getEntity().getContent();I print http content by LogCat.
BufferedReader rBuffer = new BufferedReader(new InputStreamReader(input, "UTF-8")); String readLine; try { while((readLine = rBuffer.readLine()) != null) { Log.d("HttpClientActivity", readLine);I could get yahoo's Web Page.
Source code is here.
0 件のコメント:
コメントを投稿