Tecnologia do Blogger.
RSS

[androidbrasil-dev] Re: Problema ao enviar dados ao servidor - formulario do tipo multipart/form-data

Que problema exatamente ? Tenta especificar melhor, aí fica mais fácil para nós ajudarmos.

Abs

Em terça-feira, 30 de outubro de 2012 16h59min56s UTC-2, Diego Lopes escreveu:

Pessoal,

Estou com problemas para enviar esses dados ao servidor.
Alguém pode me dizer aonde estou errando?
Obrigado

public synchronized void sendEntregaThread(final Entrega entrega, final Context context) {
        new Thread(new Runnable() {
           
            @Override
            public void run() {
                String res = null;
                try {
                    KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
                    trustStore.load(null, null);
           
                    SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
                    sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
                   
                    HttpParams params = new BasicHttpParams();
                    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
                    HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

                    SchemeRegistry registry = new SchemeRegistry();
                    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
                    registry.register(new Scheme("https", sf, 8080));

                    ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
                   
                    HttpClient httpClient = new DefaultHttpClient(ccm, params);
                    HttpPost postRequest = new HttpPost("MEU SERVIÇO DE ENTREGA AO SERVIDOR");
                   
                   
                    MultipartEntity multipartContent = new MultipartEntity();

                    try {
                        if ((entrega.getImg() != null) && (!entrega.getImg().equals(""))) {
                            InputStreamBody photoFis = new InputStreamBody( new FileInputStream( new File(entrega.getImg()) ), entrega.getImg() );
                            multipartContent.addPart("img_canhoto", photoFis);
                        }
                    } catch (FileNotFoundException e) {}       
                    try {
                        if ((entrega.getVideo() != null) && (!entrega.getVideo().equals(""))) {
                            InputStreamBody videoFis = new InputStreamBody( new FileInputStream( new File(entrega.getVideo()) ), entrega.getVideo() );
                            multipartContent.addPart("video", videoFis);
                        }
                    } catch (FileNotFoundException e) {}
                                   
                    multipartContent.addPart("video",new StringBody(entrega.getVideo()));
                    multipartContent.addPart("assinatura", new StringBody(entrega.getAssinatura()));
                    multipartContent.addPart("foto", new StringBody(entrega.getImg())  );
                    multipartContent.addPart("dataEntrega",new StringBody(entrega.getDataEntrega()) );
                   
                    postRequest.setEntity(multipartContent);
                    ResponseHandler<String> responseHandler = new BasicResponseHandler();
                   
                    res = httpClient.execute(postRequest, responseHandler);
                  
                  
                } catch (SocketException e) {
                    Log.e(Constants.TAG, e.getMessage(), e);
                    res = "ERROR";
                  
                } catch (Throwable e) {
                    Log.e(Constants.TAG, e.getMessage(), e);
                    res = "ERROR";
                  
                }
                NetConnectivityListener.isSync = false;
                Log.i(Constants.TAG, res);
                insertEntrega(entrega, context);
            }
           
        }).start();
    }


--
 
 

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário