Advertisement
Guest User

Code - Login post to server

a guest
Oct 9th, 2012
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. public static String makeWebCall(String url, String uname, String pass) {
  2.      
  3.         System.out
  4.         .println("@#$@#@$#$@#$@$##$-----FOR LOGIN-------->>>>>>>>>>>>> ---------->");
  5.         HttpPost post = new HttpPost(url);
  6.  
  7.         List<NameValuePair> params = new ArrayList<NameValuePair>();
  8.  
  9.         params.add(new BasicNameValuePair("username", uname));
  10.         params.add(new BasicNameValuePair("password", pass));
  11.  
  12.         UrlEncodedFormEntity formEntity = null;
  13.         try {
  14.             formEntity = new UrlEncodedFormEntity(params);
  15.            
  16.         } catch (UnsupportedEncodingException e1) {
  17.             // TODO Auto-generated catch block
  18.             e1.printStackTrace();
  19.         }
  20.  
  21.         post.setEntity(formEntity);
  22.        
  23.         try {
  24.             // post.setEntity(new StringEntity(requestString));
  25.  
  26.             HttpResponse response = client.execute(post);
  27.             System.out.println("=========> Responsehello login ========> " + response);
  28.             int statusCode = response.getStatusLine().getStatusCode();
  29.             System.out.println("=========> statusCode login => " + statusCode);
  30.             if (statusCode == HttpStatus.SC_OK) {
  31.                 HttpEntity entity = response.getEntity();
  32.                 InputStream is = entity.getContent();
  33.                
  34.                 String StreamValue = iStream_to_String(is);
  35.                
  36.                 if (entity != null) {
  37.                     //post.abort();
  38.                    
  39.                     EntityUtils.consume(entity);
  40.                     is.close();
  41.                     //response.getEntity().consumeContent();
  42.                      
  43.                  }
  44.                
  45.                 return StreamValue;
  46.             } else {
  47.                 return "Hello This is LOGIN status ==> :"
  48.                         + String.valueOf(statusCode);
  49.             }
  50.         } catch (UnsupportedEncodingException e) {
  51.             // TODO Auto-generated catch block
  52.             e.printStackTrace();
  53.         } catch (ClientProtocolException e) {
  54.             // TODO Auto-generated catch block
  55.             e.printStackTrace();
  56.         } catch (IOException e) {
  57.             // TODO Auto-generated catch block
  58.             e.printStackTrace();
  59.         }
  60.  
  61.         return null;
  62.  
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement