URL url = new URL(“http://10.1.44.127:8001/loc”);
//参数
StringBuilder parameterbulider = new StringBuilder();
//响应
StringBuilder responseBuilder = new StringBuilder();
BufferedReader reader = null;
PrintWriter out = null;
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setInstanceFollowRedirects(false);
//post 请求必须设置此处
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setDefaultUseCaches(false);
conn.setConnectTimeout(30 * 1000);
conn.setReadTimeout(30 * 1000);
conn.setRequestMethod("POST");
//多个参数拼接
parameterbulider.append("qt=misc");
String key = parameter.getKey();
if (StringUtil.isEmpty(key))
{
key = "tv2j11111T644qC2oR22EF";
}
parameterbulider.append("&Ak=" + key);
if (parameter.getImei() == null)
{
parameterbulider.append("&Imei=");
}
else
{
parameterbulider.append("&Imei=" + parameter.getImei());
}
out = new PrintWriter(conn.getOutputStream());
out.print(parameterbulider.toString());
out.flush();
reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null)
{
responseBuilder.append(line + "\n");
}
reader.close();
String result = responseBuilder.toString();