Before:
DataInputStream in = new DataInputStream (Connection.getinputstream ());
Byte[] B = new byte[in.available ()];
In.read (b);
After:
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"));
}
Out.flush ();
Out.close ();
BufferedReader br = new BufferedReader (New InputStreamReader (Connection.getinputstream (), "Utf-8"));
StringBuilder sb=new StringBuilder ();
String str;
while ((Str=br.readline ())!=null) {
Sb.append (str);
}
return sb.tostring ();
}
Read byte inconsistency resolution using DataOutputStream output stream inconsistent with local and test environments