new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
// TODO Auto-generated method stub
String path = "http://www.shopmanage.com/landlady/spm";
// String path = "http://221.12.165.250:40403/site/loginmainapp";
//Post请求
HttpPost postRequest = new HttpPost(path);
//准备参数列表,泛型为基本键值对
List<NameValuePair> params = new ArrayList<NameValuePair>();
// 添加参数
params.add(new BasicNameValuePair("id", id));
try {
UrlEncodedFormEntity se = new UrlEncodedFormEntity(params, HTTP.UTF_8);
postRequest.setEntity(se);
// 执行请求,获得服务器响应
HttpResponse response = new DefaultHttpClient().execute(postRequest);
// 判断响应头文件的状态码
int postcode = response.getStatusLine().getStatusCode();
if (postcode == 200) {
// 获取响应实体对象,提取信息
String strResult= EntityUtils.toString(response.getEntity());
Log.i("MainActivity", strResult);
// JSONArray array = new JSONArray(strResult);
JSONObject obj = new JSONObject(strResult);
int code = obj.getInt("code");
// MainActivity.this.flag = Boolean.parseBoolean(EntityUtils.toString(response.getEntity()).trim());
if(code == 200) {
//
}
}
else {
Log.i("Error Response:", response.getStatusLine().toString());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Looper.loop();
}
}).start();