ddkclaudio

Untitled

Jan 18th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.01 KB | None | 0 0
  1. I'm trying to Get Request with code below but the stringbuilder is always null. The url is correct...
  2.  
  3.    
  4.    public void onClick(View v) {
  5.         if( v == voltar ) {
  6.             setResult( RESULT_CANCELED );
  7.             finish( );
  8.         }
  9.         else if( v == avancar ) {
  10.             if( ! Utils.validateCPF( editCPF ) ) return;
  11.             if( ! Utils.validateEmail( editEmail ) ) return;
  12.  
  13.             final ProgressDialog dialog = ProgressDialog.show( this, "Verificando", "Por favor, aguarde...", true );
  14.             final String edCpf = editCPF.getCleanText();
  15.             final String edEmail = editEmail.getText().toString();
  16.             final Activity instance = this;
  17.  
  18.             Runnable runnable = new Runnable() {
  19.                 public void run() {
  20.  
  21.                     String reqUrl = "http://url/login?";
  22.                     String reqParams = "";
  23.                     try {
  24.                         reqParams = "cpf=" + URLEncoder.encode( edCpf, "UTF-8" ) +"&email=" +/* URLEncoder.encode( edEmail, "UTF-8" )*/ (String) edEmail;
  25.                     } catch (UnsupportedEncodingException e1) {
  26.                         e1.printStackTrace();
  27.                     }
  28.                          Log.d("",reqUrl + reqParams);
  29.                     StringBuilder is = Utils.sendHttpGet( reqUrl + reqParams );
  30.                            
  31.                     instance.runOnUiThread( new Runnable() {
  32.                         public void run() {
  33.                             dialog.dismiss( );
  34.                         }
  35.                     });
  36.  
  37.                     String msg = null;
  38.                     if( is == null ) {
  39.                         msg = "Erro ao verificar cadastro.\nCertifique-se de que a conexão com a internet esteja ativada e tente novamente.";
  40.                     }
  41.                     else {
  42.                         msg = "Erro interno ao verificar cadastro.";
  43.                         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  44.                         try {
  45.                             DocumentBuilder builder = factory.newDocumentBuilder( );
  46.                             Document dom = builder.parse( new ByteArrayInputStream( is.toString().getBytes() ) );
  47.                             Element  root = dom.getDocumentElement( );
  48.                             NodeList list = root.getElementsByTagName( "UserClientEntity" );
  49.                             if( list.getLength() < 1 ) {
  50.                                 msg = "Usuário não encontrado.";
  51.                             }
  52.                             else {
  53.                                 String cpf = "";
  54.                                 msg = "Usuário não encontrado.";
  55.  
  56.                                 NodeList user = list.item( 0 ).getChildNodes( );
  57.        
  58.                                 for( int i = 0; i < user.getLength(); ++i ) {
  59.                                     if( user.item( i ).getNodeName().equals( "cpf" ) ) {
  60.                                         cpf = user.item( i ).getChildNodes().item(0).getNodeValue();
  61.                                         if( cpf == null ) {
  62.                                             cpf = "";
  63.                                         }
  64.                                         break;
  65.                                     }
  66.                                 }
  67.  
  68.                                 if( cpf.equals( edCpf ) ) {
  69.            
  70.                                     instance.runOnUiThread( new Runnable() {
  71.                                         public void run() {
  72.                                             LastLoginData.setCpf( edCpf );
  73.                                             LastLoginData.setEmail( edEmail );
  74.                                             LastLoginData.saveData( instance );
  75.  
  76.                                             setResult( RESULT_OK );
  77.                                             finish( );
  78.                                         }
  79.                                     });
  80.                                     msg = null;
  81.                                 }
  82.                             }
  83.                         }
  84.                         catch( Exception e ) {
  85.                         }
  86.                     }
  87.                     if( msg != null ) {
  88.                         final String xmsg = msg;
  89.                         instance.runOnUiThread( new Runnable() {
  90.                             public void run() {
  91.                                 Utils.showInformation( instance, "Atenção", xmsg );
  92.                             }
  93.                         });
  94.                     }
  95.                 }
  96.             };
  97.             Thread thread = new Thread( runnable );
  98.             thread.start( );
  99.         }
  100.     }
Advertisement
Add Comment
Please, Sign In to add comment