Это упрощение кода, из которого я печатаю :
Код: Выделить всё
HttpURLConnection con;
try {
Log.v(TAG, "utilityBOopreation:Connect: entrato nel connect");
URL url = new URL(urlAddress);
con = (HttpURLConnection) url.openConnection();
// set propertis
con.setRequestMethod("POST");
con.setConnectTimeout(1000);
con.setReadTimeout(1000);
con.setRequestProperty("Content-Type","application/json");
con.setRequestProperty("Accept", "application/json");
con.setDoInput(true);
con.setDoOutput(true);
// Log.v(TAG, "utilityBOopreation:Connect: Valore della connessione : " + con);
con.connect();
JSONObject jo= new JSONObject();
try {
jo.put("ID",Id);
jo.put("GRM",GRM);
/ .
altri campi
./
Код: Выделить всё
// Write
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os,"UTF-8"));
bw.write(jo.tostring());
Log.v(TAG,"Sender: Send : Il packData è stato inviato ");
bw.flush();
// RELEASE RES
// Verifico i valori dolpo l' invio dei dati
Log.v(TAG,"Sender: Send : Il risultato del HttpURLConnection " +
"Dopo l'invio dello streaming dati : " + con);
Log.v(TAG,"Sender: Send : Il risultato del outputstreaming : " + os);
bw.close();
os.close();
} catch (MalformedURLException e) {
e.printStackTrace();
Log.v(TAG, "utilityBOopreation:Connect: La connessione non è andata a buon fine : " + e);
return null;
} catch (IOException e) {
e.printStackTrace();
Log.v(TAG, "utilityBOopreation:Connect: La connessione non è andata a buon fine : " + e);
return null;
} catch (JSONException | UnsupportedEncodingException e) {
e.printStackTrace();
Log.v(TAG,"DataPackager:packData:non sono riuscito a creare il json ... " + e.getMessage());
}
Код: Выделить всё
Подробнее здесь: [url]https://stackoverflow.com/questions/49656121/how-do-i-know-if-im-sending-the-file-with-outputstream[/url]
Мобильная версия