{
// 这里写入子线程需要做的工作
String path = "http://192.168.10.251:8081/upload.jsp";
HttpPost httpRequest = new HttpPost(path);
/*
* NameValuePair实现请求参数的封装
try {
gps.put("latitude", latitude);
gps.put("longitude", longitude);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//将Josn放到post请求中
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("json", gps.toString()));
try {
/* 添加请求参数到请求对象 */
httpRequest.setEntity(new UrlEncodedFormEntity(params,
HTTP.UTF_8));
/* 发送请求并等待响应 */
HttpResponse httpResponse = new DefaultHttpClient()
.execute(httpRequest);
/* 若状态码为200 ok */
if (httpResponse.getStatusLine().getStatusCode() != 404) {
/* 读返回数据 */
String strResult = EntityUtils
.toString(httpResponse.getEntity());
Log.i(TAG, strResult);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
// 这里写入子线程需要做的工作
String path = "http://192.168.10.251:8081/upload.jsp";
HttpPost httpRequest = new HttpPost(path);
/*
* NameValuePair实现请求参数的封装
*/
//封装数据到JSON
JSONObject gps = new JSONObject();try {
gps.put("latitude", latitude);
gps.put("longitude", longitude);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//将Josn放到post请求中
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("json", gps.toString()));
try {
/* 添加请求参数到请求对象 */
httpRequest.setEntity(new UrlEncodedFormEntity(params,
HTTP.UTF_8));
/* 发送请求并等待响应 */
HttpResponse httpResponse = new DefaultHttpClient()
.execute(httpRequest);
/* 若状态码为200 ok */
if (httpResponse.getStatusLine().getStatusCode() != 404) {
/* 读返回数据 */
String strResult = EntityUtils
.toString(httpResponse.getEntity());
Log.i(TAG, strResult);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});