Page 117 - 24JAM_Pintar_Pemrograman_Android__1-libre
P. 117
24 JAM!! Pintar Pemrograman Android
37: HttpClient klien = getHttpClient();
38: HttpPost req = new HttpPost(url);
39: UrlEncodedFormEntity formEntity = new
UrlEncodedFormEntity(
40: postParameter);
41: req.setEntity(formEntity);
42: HttpResponse jawaban = klien.execute(req);
43: in = new BufferedReader(new
InputStreamReader(jawaban.getEntity().getContent()));
44: StringBuffer sb = new StringBuffer("");
45: String line = "";
46: String NL = System.getProperty("line.separator");
47: while ((line = in.readLine()) != null) {
48: sb.append(line + NL);
49: }
50: in.close();
51: String hasil = sb.toString();
52: return hasil;
53: } finally {
54: if (in != null) {
55: in.close();
56: }
57: }
58:
59: }
60:
61: public static String eksekusiHttpGet(String url) throws
Exception {
62: BufferedReader in = null;
63: try {
64: HttpClient hc = getHttpClient();
65: HttpGet req = new HttpGet();
66: req.setURI(new URI(url));
67: HttpResponse resp = hc.execute(req);
68: in = new BufferedReader(new
InputStreamReader(resp.getEntity().getContent()));
69: StringBuffer sb = new StringBuffer("");
70: String line = "";
71: String NL = System.getProperty("line.separator");
72: while ((line = in.readLine()) != null) {
73: sb.append(line + NL);
74: }
75: in.close();
76: String hasil = sb.toString();
77: return hasil;
78: } finally {
79: if (in != null) {
80: in.close();
81: }
82: }
83: }
84: }
85:
5. Pada phplogin.java ubah kodenya seperti dibawah ini
Dapatkan materi terbaru di 117
www.omayib.com

