Skip to content

Instantly share code, notes, and snippets.

@oludouglas
Created June 17, 2016 09:09
Show Gist options
  • Save oludouglas/bc951ef95976d815630d231a3f99ccb0 to your computer and use it in GitHub Desktop.
Save oludouglas/bc951ef95976d815630d231a3f99ccb0 to your computer and use it in GitHub Desktop.
OutputStream os = null;
InputStream is = null;
HttpURLConnection conn = null;
try {
URL url = new URL(
"http://aristeu.pt/aristGas/ws/cliente/index.php/");
JSONObject jsonParam = new JSONObject();
jsonParam.put("Nome", "");
jsonParam.put("Email", "");
jsonParam.put("Morada", "");
jsonParam.put("CodigoPostal", "");
jsonParam.put("Localidade", "");
jsonParam.put("Contribuinte", "");
jsonParam.put("Telemovel", "");
jsonParam.put("Telefone", "");
jsonParam.put("Password", "");
jsonParam.put("CodigoAcesso", "");
jsonParam.put("Ativo", 1);
String message = jsonParam.toString();
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setFixedLengthStreamingMode(message.getBytes().length);
// add necessary HTTP headers
conn.setRequestProperty("Content-Type",
"application/json;charset=utf-8");
conn.setRequestProperty("X-Requested-With", "XMLHttpRequest");
// open your connection
conn.connect();
// setup send
os = new BufferedOutputStream(conn.getOutputStream());
os.write(message.getBytes());
// clean up
os.flush();
// get your response via Inputstream
is = conn.getInputStream();
} catch (Exception e) {
Log.v("Error Here", e.getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment