M0286_Libro Curso
Android
Necesitamos crear la clase RestClient.java que define el cliente REST. Implementaremos las librerías de org.apache.http incluidas en Android para realizar las conexiones al Servicio Web. Su código será el siguiente: package com.seas.ejemplo.RestService;
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URLEncoder; import java.util.ArrayList;
import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; public class RestClient { // definimos las variables para los parametros y cabeceras private ArrayList
private int responseCode; private String message; // definimos la variable respuesta private String response; public int getResponseCode() { return responseCode; } public String getErrorMessage() { return message; }
236
Made with FlippingBook - Online catalogs