Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public DatosConsultaAgente GetConsultaMatricula(Agente agente, String matricula) throws Exception {
- URL url = new URL(URLservice);
- HttpURLConnection con = (HttpURLConnection) url.openConnection();
- con.setDoOutput(true);
- con.setDoInput(true);
- con.setRequestProperty("Content-Type", "application/json");
- con.setRequestProperty("Accept", "application/json");
- con.setRequestMethod("POST");
- DatosConsultaAgente sendDatos = new DatosConsultaAgente();
- sendDatos.setAgente(agente);
- sendDatos.setMatricula(matricula);
- //Creo una instancia de Gson para parsear los objetos
- Gson gson = new Gson();
- byte[] outputBytes = PBE.getInstance().Encripta(gson.toJson(sendDatos)).getBytes("UTF-8");
- OutputStream os = con.getOutputStream();
- os.write(outputBytes);
- os.flush();
- if (con.getResponseCode() != HttpURLConnection.HTTP_OK &&
- con.getResponseCode() != HttpURLConnection.HTTP_ACCEPTED &&
- con.getResponseCode() != HttpURLConnection.HTTP_CREATED){
- throw new RuntimeException("Failed : HTTP error code : "
- + con.getResponseCode());
- }
- BufferedReader br = new BufferedReader(new InputStreamReader(
- (con.getInputStream())));
- String output;
- System.out.println("Output from Server .... \n");
- StringBuilder responseString = new StringBuilder();
- while ((output = br.readLine()) != null) {
- System.out.println(output);
- responseString.append(output);
- }
- con.disconnect();
- DatosConsultaAgente datosRespuesta = gson.fromJson(responseString.toString(), DatosConsultaAgente.class);
- return datosRespuesta;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement