Foros       Consigue tu camiseta aquí
ayuda webservices

 
Publicar Nuevo Tema   Responder al Tema    Índice del Foro www.Android-Spa.com -> General
Mostrar mensajes anteriores:   

Isaacq652

Mensajes: 28
MensajePublicado: Lun Feb 13, 2012 12:52 am    Título del mensaje: ayuda webservices Enviar mensaje privado Responder citando

alguien me puede ayudar con un codigo para consumir un webservices?

duca

Mensajes: 49
MensajePublicado: Lun Feb 13, 2012 3:30 am    Título del mensaje: Enviar mensaje privado Responder citando

Que necesitas más exactamente.

Código :
/**
 * Metodo que nos permite enviar archivos grandes por el metodo multi-parte
 * @param fotos
 * @return
 */

    public static int envioFoto(HashMap fotos) {
       

        HttpURLConnection connection = null;
        DataOutputStream outputStream = null;
        FileInputStream fileInputStream  = null;

        String urlServer = "http://www.tuwebservice/clasecontroladora";
       
        String lineEnd = "\r\n";
        String twoHyphens = "--";
        String boundary = "*****";
        int serverResponseCode = 0;
        int bytesRead, bytesAvailable, bufferSize;
        byte[] buffer;
        int maxBufferSize = 1 * 1024 * 1024;
        {
           
            try {
                fileInputStream = new FileInputStream(
                        (File) fotos.get("file"));

                URL url = new URL(urlServer);
                connection = (HttpURLConnection) url.openConnection();

                // Allow Inputs & Outputs
                connection.setDoInput(true);
                connection.setDoOutput(true);
                connection.setUseCaches(false);

                // Enable POST method
                connection.setRequestMethod("POST");

                connection.setRequestProperty("Connection", "Keep-Alive");
                connection.setRequestProperty("Content-Type",
                        "multipart/form-data;boundary=" + boundary);

                outputStream = new DataOutputStream(
                        connection.getOutputStream());
                //outputStream.writeBytes((String) fotos.get("user"));
                //TODO:outputStream.writeBytes((String) fotos.get("idUser"));
                outputStream.writeBytes(twoHyphens + boundary + lineEnd);
                outputStream
                        .writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\""
                                + fotos.get("file") + "\"" + lineEnd);
                outputStream.writeBytes(lineEnd);

                bytesAvailable = fileInputStream.available();
                bufferSize = Math.min(bytesAvailable, maxBufferSize);
                buffer = new byte[bufferSize];

                // Read file
                bytesRead = fileInputStream.read(buffer, 0, bufferSize);

                while (bytesRead > 0) {
                    outputStream.write(buffer, 0, bufferSize);
                    bytesAvailable = fileInputStream.available();
                    bufferSize = Math.min(bytesAvailable, maxBufferSize);
                    bytesRead = fileInputStream.read(buffer, 0, bufferSize);
                }

                outputStream.writeBytes(lineEnd);
                outputStream.writeBytes(twoHyphens + boundary + twoHyphens
                        + lineEnd);

                // Responses from the server (code and message)
                serverResponseCode = connection.getResponseCode();
                // String serverResponseMessage =
                // connection.getResponseMessage();

                fileInputStream.close();
                outputStream.flush();
                outputStream.close();
               
            } catch (Exception ex) {
                // Exception handling
            }finally
            {
                return serverResponseCode;
            }
        }
    }

Este lo uso para pasar y recibir datos, user pass, etc.

public static String paraLogin(HashMap login,String clave) {
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://www.tuwebservice");
       
        String permiso = "";
       
        try {
           
            List<NameValuePair> nameValuePairs = null;
            if(clave.equalsIgnoreCase("login"))
            {
            nameValuePairs = new ArrayList<NameValuePair>(3);
            // cargamos los datos de la pantalla login para enviarlos a
            // comprobar
            String em=(String) login.get("user");
            nameValuePairs.add(new BasicNameValuePair("email", em));
            if(Inicio.prefs.getBoolean("autoPass",true)){
                nameValuePairs.add(new BasicNameValuePair("password",(String) login.get("pass") ));
               
            }else{
                String passw=md5((String) login.get("pass"));
                nameValuePairs.add(new BasicNameValuePair("password",passw));
               
            }
           
           
            String idioma = (String) login.get("idioma");
            nameValuePairs.add(new BasicNameValuePair("idioma",idioma));
           
           
            //este parametro sirve para que tere reconozca la acción que estoy enviando
            nameValuePairs.add(new BasicNameValuePair("logueo", "true"));
            }
   


Asi por encima creo que esto te servirá.

tina2012

Mensajes: 12
MensajePublicado: Mie Mar 21, 2012 6:46 am    Título del mensaje: the activation of office 2010 Enviar mensaje privado Responder citando

My company has many the activation key of office 2010 .As we known, the purchase of the right to use of this software is very expensive.The activation of office 2010 is very favorable in my company . compared to the purchase price , we only need spend a little money on it. available for your choice is many.Such asmicrosoft office 2010
office standard 2010]microsoft office2010
office proffesional 2010
office 2010 student discount,
office home business 2010
visio premium 2010
microsoft home and student 2010 download。If you want to buy office 2010, You can visit our website to find out you need information .Through
reading and understooding ,we can know the good.If you had buy my company's products, I am sure you will not regret it.Our company's aim is first-class service, top quality, second-rate prices.You will be satisfied with the product.

tina2012

Mensajes: 12
MensajePublicado: Mie Mar 21, 2012 7:18 am    Título del mensaje: buy android phone Enviar mensaje privado Responder citando

Our company have a large amout of android phones for sale ,there are many kind of phones ,which are suply you to chose.such as 3G android phone , gsm android phones , android phones 2012 , dual sim android phone , [url=http://www.lovebargaining.com/-Discount-cell-phone-and phone-cell-phone_c801.html]wcdma phone[/url] smallest android phone ,
android phone with keyboard.
http://www.lovebargaining.com/

Publicar Nuevo Tema   Responder al Tema    Índice del Foro www.Android-Spa.com -> General Todas las horas están en GMT + 2 Horas
Página 1 de 1
Ver tema anterior :: Ver siguiente tema  

 
Saltar a:  
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas