/**
* Request Post
* @Title: Gethttpurlconnection
* @Description: TODO (here is a word describing the effect of this method)
* @param: @param url1
* @param: @param paream
* @param: @return
* @param: @throws IOException
* @param: @throws jsonexception
* @return: String
* @throws
* @author Ecar
* @Date 2016-7-23 03:08:59
*/
private string Gethttpurlconnection (String url1,string paream) throws IOException, Jsonexception
{
Long deviceid=1l;
URL url = new URL (URL1);
HttpURLConnection connection = (httpurlconnection) url.openconnection ();
Connection.setrequestmethod ("POST");
Connection.setrequestproperty ("Content-type", "application/json;charset=utf-8");
Connection.setconnecttimeout (80*1000);
Connection.setreadtimeout (80*1000);
Connection.setdoinput (TRUE);
Connection.setdooutput (TRUE);
Connection.connect ();
DataOutputStream out = new DataOutputStream (Connection.getoutputstream ());
Out.writelong (DEVICEID);
Shortest
Jsonarray array = new Jsonarray (paream);
Out.writeshort (Array.Length ());
for (int i=0;i<array.length (); i++) {
Jsonobject obj = Array.getjsonobject (i);
Out.write (Obj.getstring ("Time"). GetBytes ("UTF8"));
Double d = obj.getdouble ("Lon");
int lon = (int) (d * 1000000);
Out.writeint (LON);
D = obj.getdouble ("lat");
int lat = (int) (d * 1000000);
Out.writeint (LAT);
Out.writefloat ((float) obj.getdouble ("Speed"));
Out.writefloat ((float) obj.getdouble ("Direc"));
}
Call Mode:
String ss = "[";
String date = new Java.text.SimpleDateFormat ("YYYYMMDDHHMMSS"). Format (new java.util.Date ());
Gps gps= positionutil.gcj_to_gps84 (double.valueof (split[1]), double.valueof (split[0]));//conversion to 84 coordinate system
Gps gps1= positionutil.gcj_to_gps84 (double.valueof (split02[1]), double.valueof (split02[0]));//conversion to 84 coordinate system
Gps gps2= positionutil.gcj_to_gps84 (double.valueof (split03[1]), double.valueof (split03[0]));//conversion to 84 coordinate system
ss+= "{\" time\ ": \" "+date+" \ ", \" lon\ ":" +gps.getwglon () + ", \" lat\ ":" +gps.getwglat () + ", \" speed\ ": 20,\" direc\ ": 0},";
ss+= "{\" time\ ": \" "+date+" \ ", \" lon\ ":" +gps1.getwglon () + ", \" lat\ ":" +gps1.getwglat () + ", \" speed\ ": 30,\" direc\ ": 0}, ";
ss+= "{\" time\ ": \" "+date+" \ ", \" lon\ ":" +gps2.getwglon () + ", \" lat\ ":" +gps2.getwglat () + ", \" speed\ ": 30,\" direc\ ": 0}" ;
ss+= "]";
String param=gethttpurlconnection (uriapi+ "/ROUTETRAFFICINFOSEARCH?BIZCODE=FBAYM29ZX11KVKBUQVNJ", SS);
System.out.println (param);
Returns data in XML format
Out.flush ();
Out.close ();
DataInputStream in = new DataInputStream (Connection.getinputstream ());
int len = in.available ();
Byte[] B = new Byte[len];
In.read (b);
System.out.println (New String (b, "Utf-8"));
return new String (b, "Utf-8");
}
Use stream to go to post request to solve Chinese garbled problem return XML format