private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case 0:
obj = (String)msg.obj;
try{
list = resolve(obj);
}catch (Exception e){}
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
test();
try{
list = resolve(obj);
}catch (Exception e){
}
}
});
}
public void test(){
new Thread(new Runnable() {
@Override
public void run() {
try {
//发送POST请求
URL url = new URL("http://jydsj.chinaecdc.com/app/banner/list");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setUseCaches(false);
conn.setDoOutput(true);
//设置请求头,不设置使用默认设置
conn.setRequestProperty("Content-Length", ""+"{\"params\": {\"from\": \"Android\"}}".length() );
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
out.write("{\"params\": {\"from\": \"Android\"}}");
out.flush();
out.close();
//获取响应状态
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
System.out.println("connect failed!");
}
//获取响应内容体
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
while ((line = in.readLine()) != null) {
result += line + "\n";
}
//Looper准备
Looper.prepare();
//handler发送消息
Message msg = new Message();
msg.what=0;
msg.obj=result;
handler.sendMessage(msg);
in.close();
} catch (
IOException e) {
e.printStackTrace(System.out);
}
}
}).start();
}
//json解析
private ArrayList<HashMap<String,Object>> resolve(String json) {
try {
JSONObject jsonObject = new JSONObject(json);
String swe = jsonObject.getString("message");
Toast.makeText(getApplicationContext(),swe,Toast.LENGTH_SHORT).show();
System.out.print(swe);
}catch (Exception e){
}
return list;
}private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case 0:
obj = (String)msg.obj;
try{
list = resolve(obj);
}catch (Exception e){}
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
test();
try{
list = resolve(obj);
}catch (Exception e){
}
}
});
}
public void test(){
new Thread(new Runnable() {
@Override
public void run() {
try {
//发送POST请求
URL url = new URL("http://jydsj.chinaecdc.com/app/banner/list");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setUseCaches(false);
conn.setDoOutput(true);
//设置请求头,不设置使用默认设置
conn.setRequestProperty("Content-Length", ""+"{\"params\": {\"from\": \"Android\"}}".length() );
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
out.write("{\"params\": {\"from\": \"Android\"}}");
out.flush();
out.close();
//获取响应状态
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
System.out.println("connect failed!");
}
//获取响应内容体
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
while ((line = in.readLine()) != null) {
result += line + "\n";
}
//Looper准备
Looper.prepare();
//handler发送消息
Message msg = new Message();
msg.what=0;
msg.obj=result;
handler.sendMessage(msg);
in.close();
} catch (
IOException e) {
e.printStackTrace(System.out);
}
}
}).start();
}
//json解析
private ArrayList<HashMap<String,Object>> resolve(String json) {
try {
JSONObject jsonObject = new JSONObject(json);
String swe = jsonObject.getString("message");
Toast.makeText(getApplicationContext(),swe,Toast.LENGTH_SHORT).show();
System.out.print(swe);
}catch (Exception e){
}
return list;
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case 0:
obj = (String)msg.obj;
try{
list = resolve(obj);
}catch (Exception e){}
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
test();
try{
list = resolve(obj);
}catch (Exception e){
}
}
});
}
public void test(){
new Thread(new Runnable() {
@Override
public void run() {
try {
//发送POST请求
URL url = new URL("http://jydsj.chinaecdc.com/app/banner/list");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setUseCaches(false);
conn.setDoOutput(true);
//设置请求头,不设置使用默认设置
conn.setRequestProperty("Content-Length", ""+"{\"params\": {\"from\": \"Android\"}}".length() );
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
out.write("{\"params\": {\"from\": \"Android\"}}");
out.flush();
out.close();
//获取响应状态
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
System.out.println("connect failed!");
}
//获取响应内容体
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
while ((line = in.readLine()) != null) {
result += line + "\n";
}
//Looper准备
Looper.prepare();
//handler发送消息
Message msg = new Message();
msg.what=0;
msg.obj=result;
handler.sendMessage(msg);
in.close();
} catch (
IOException e) {
e.printStackTrace(System.out);
}
}
}).start();
}
//json解析
private ArrayList<HashMap<String,Object>> resolve(String json) {
try {
JSONObject jsonObject = new JSONObject(json);
String swe = jsonObject.getString("message");
Toast.makeText(getApplicationContext(),swe,Toast.LENGTH_SHORT).show();
System.out.print(swe);
}catch (Exception e){
}
return list;
}private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what){
case 0:
obj = (String)msg.obj;
try{
list = resolve(obj);
}catch (Exception e){}
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
test();
try{
list = resolve(obj);
}catch (Exception e){
}
}
});
}
public void test(){
new Thread(new Runnable() {
@Override
public void run() {
try {
//发送POST请求
URL url = new URL("http://jydsj.chinaecdc.com/app/banner/list");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setUseCaches(false);
conn.setDoOutput(true);
//设置请求头,不设置使用默认设置
conn.setRequestProperty("Content-Length", ""+"{\"params\": {\"from\": \"Android\"}}".length() );
OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
out.write("{\"params\": {\"from\": \"Android\"}}");
out.flush();
out.close();
//获取响应状态
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
System.out.println("connect failed!");
}
//获取响应内容体
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
while ((line = in.readLine()) != null) {
result += line + "\n";
}
//Looper准备
Looper.prepare();
//handler发送消息
Message msg = new Message();
msg.what=0;
msg.obj=result;
handler.sendMessage(msg);
in.close();
} catch (
IOException e) {
e.printStackTrace(System.out);
}
}
}).start();
}
//json解析
private ArrayList<HashMap<String,Object>> resolve(String json) {
try {
JSONObject jsonObject = new JSONObject(json);
String swe = jsonObject.getString("message");
Toast.makeText(getApplicationContext(),swe,Toast.LENGTH_SHORT).show();
System.out.print(swe);
}catch (Exception e){
}
return list;
}