80,493
社区成员
发帖
与我相关
我的任务
分享
public String clickInfo_Java() {
String result = "";
try {
final String SERVER_URL = "http://10.0.2.2:8080/tm/AndroidAction_Android_FindByCarNumber"; // 定义需要获取的内容来源地址
HttpPost request = new HttpPost(SERVER_URL); // 根据内容来源地址创建一个Http请求
request.setHeader("Content-Type", "application/x-www-form-urlencoded");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("cardnumber", "123124212536")); // 添加必须的参数
params.add(new BasicNameValuePair("x", Math.random() + "")); // 添加必须的参数
request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); // 设置参数的编码
// HttpResponse httpResponse = new
// DefaultHttpClient().execute(request); // 发送请求并获取反馈
HttpClient client = new DefaultHttpClient();
HttpResponse httpResponse = client.execute(request); // 解析返回的内容
if (httpResponse.getStatusLine().getStatusCode() != 404) {
result = EntityUtils.toString(httpResponse.getEntity());
System.out.println(result);
}
} catch (Exception e) {
Toast.makeText(this, e.getMessage().toString(), Toast.LENGTH_LONG)
.show();
e.printStackTrace();
}
return result;
}