https (SSL ) connectivity

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

https (SSL ) connectivity

Postby Rizwan » Sat Dec 22, 2007 1:11 pm

Hi!
Can any body tell me how to open Https connection I use the following code

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 try {
  2.  
  3.                         URL page = new URL(LoginURL);
  4.  
  5.                         URLConnection conn = (HttpURLConnection) page.openConnection(proxy);
  6.  
  7.                         // Construct data
  8.  
  9.                         String data = URLEncoder.encode("Email", "UTF-8") + "="
  10.  
  11.                                         + URLEncoder.encode(Email, "UTF-8");
  12.  
  13.                         data += "&" + URLEncoder.encode("Passwd", "UTF-8") + "="
  14.  
  15.                                         + URLEncoder.encode(Passwrd, "UTF-8");
  16.  
  17.  
  18.  
  19.                         // Send data
  20.  
  21.  
  22.  
  23.                         conn.setDoOutput(true);
  24.  
  25.                         OutputStreamWriter wr = new OutputStreamWriter(conn
  26.  
  27.                                         .getOutputStream());
  28.  
  29.                         wr.write(data);
  30.  
  31.                         wr.flush();
  32.  
  33.                         fr = conn.getInputStream();
  34.  
  35.                         int len = conn.getContentLength();
  36.  
  37.                         while (((c = fr.read()) != -1) && (--len > 0)) {
  38.  
  39.                                 buffer.append((char) c);
  40.  
  41.                         }
  42.  
  43.                         index = buffer.indexOf("Auth");
  44.  
  45.                 } catch (MalformedURLException mue) {
  46.  
  47.                         System.out.println("Bad URL: " + mue.toString());
  48.  
  49.                 } catch (IOException mue) {
  50.  
  51.                         System.out.println("Bad URL: " + mue.toString());
  52.  
  53.                 } finally {
  54.  
  55.                         if (fr != null)
  56.  
  57.                                 try {
  58.  
  59.                                         fr.close();
  60.  
  61.                                 } catch (IOException e) {
  62.  
  63.                                         e.printStackTrace();
  64.  
  65.                                 }
  66.  
  67.                 }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


and getting Exception SSL handshake failure . Can any body tell me how to connect using SSL in Android

Regards
riz
Rizwan
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Dec 16, 2007 6:35 pm

Top

Postby Rizwan » Sat Dec 22, 2007 6:25 pm

Hello!
Can body tell me what I m missing . I m really stuck here .please.............
Rizwan
Junior Developer
Junior Developer
 
Posts: 18
Joined: Sun Dec 16, 2007 6:35 pm

Postby plusminus » Sat Dec 22, 2007 6:43 pm

Hell Rizwan,

the server is probably awaiting a connection capable of handling all the SSL-Stuff like Handshaking and Encryption.
I don't know/think that the OutPutStream returned from the URLConnection is capable of such things...
You probably need to wrap something around the Stream(s).

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby libertino » Thu May 29, 2008 6:03 pm

I had similar problem. It looks like emulator has only TLS implemented, not 'real' SSL
libertino
Junior Developer
Junior Developer
 
Posts: 12
Joined: Sun May 18, 2008 3:36 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: Exabot [Bot] and 7 guests