// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("10.0.2.2:90/jsonTest.php";);
JSONObject json = new JSONObject();
try {
json.put("name", "flower");
json.put("position", "student");
JSONArray postjson=new JSONArray();
postjson.put(json);
httppost.setHeader("json",json.toString());
httppost.getParams().setParameter("jsonpost",postjson);
System.out.print(json);
HttpResponse response = httpclient.execute(httppost);
if(response != null)
{
InputStream is = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
text = sb.toString();
}
tv.setText(text);
}catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
Trang Chủ
Android
PHP
Chuỗi
Dialog
Clipboard
Spinner
Auto Layout
ActionBar
Intent
Random
SQL
Admod
Version
TextView
Tabhost
Json
ListView
Time Picker
Calendar
Ham
FloatingActionMenu
Button
EditText
Activity
Custom Adapter
Xoay Màn Hình
Wifi & 3G
Lỗi
Fragment
Shape
SMS
Push
FireBase
CheckBox
Mảng
Facebook
Timer
Service
Text To Speech
Recycler View
Search This Blog
Thursday, October 27, 2016
Service - Gửi Json lên api
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment