473,395 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

SSL Client Side

The task is to implement a client, which would connect to a remote host using https protocol, and print on screen the html file. I can do it successfully by using http protocol, but when I add the ssl part, it can not work. the code is like below
Expand|Select|Wrap|Line Numbers
  1. import java.net.*; 
  2. import javax.net.ssl.*;
  3. import java.security.*; 
  4.  
  5. class ReadURL { 
  6.     static final String TRUSTSTORE = "myStore.ks";
  7.     static final String TRUSTSTOREPASSWD = "12345";
  8.     public static void main(String[] args) throws IOException{ 
  9.         try {
  10.             SSLContext sslContext = SSLContext.getInstance( "TLS" );
  11.             KeyStore ts = KeyStore.getInstance("JCEKS");
  12.             ts.load(new FileInputStream(TRUSTSTORE), TRUSTSTOREPASSWD.toCharArray());
  13.             TrustManagerFactory tfm = TrustManagerFactory.getInstance("SunX509");
  14.             tfm.init(ts);
  15.             sslContext.init(null, tfm.getTrustManagers(), null );
  16.             SSLSocketFactory sslFact = sslContext.getSocketFactory();
  17.  
  18.             SSLSocket client = (SSLSocket)sslFact.createSocket("localhost", 8082);
  19.             client.setEnabledCipherSuites( client.getSupportedCipherSuites() );
  20.  
  21.             URL url = new URL("https://localhost:8082/");
  22.             BufferedReader in = new BufferedReader( 
  23.                 new InputStreamReader(url.openStream())); 
  24.             String inputLine; 
  25.  
  26.             while ((inputLine = in.readLine()) != null) { 
  27.                 // Process each line.
  28.                 System.out.println(inputLine); 
  29.             } 
  30.             in.close(); 
  31.  
  32.  
  33.         } catch (MalformedURLException me) { 
  34.             System.out.println(me); 
  35.  
  36.         } catch (IOException ioe) { 
  37.             System.out.println(ioe); 
  38.         } 
  39.     catch (Exception e) {
  40.       System.err.println("Communication error " + e);
  41.       e.printStackTrace();
  42.     }
  43.     }//end main 
  44. }//end class ReadURL
  45.  
Can someone help me? Many thanks.
Mar 28 '09 #1
1 1706
JosAH
11,448 Expert 8TB
Please describe 'it can not work' for us; what doesn't work? Does it compile? Does it run? Does it throw an exception? What is the stack trace? Please help us to help you.

kind regards,

Jos
Mar 29 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Kathryn | last post by:
Hiya I have a problem with using some client side and server side scripting together in an ASP. I'm using VBScript. What I'm trying to achieve is this - - Page loads up and some server side...
11
by: Tom Leylan | last post by:
(I posted this in languages.vb also... I can't figure out where things go if you use a little of a lot of things) Hi all... I'm looking for an example (or a pointer to one) related to the...
2
by: Dicky Cheng | last post by:
Hi, I am using .net remoting technology. I set up a .net remoting client and server in IIS. When the client calls the server, the server will run a long duration method (30-60seconds). I have a...
18
by: cjl | last post by:
Hey all: I know that it is silly in the age of Google to 'lose' something on the internet, but I recently checked out a project that had implemented a database with a subset of SQL in pure...
6
by: Ken Allen | last post by:
I am relatively new to .Net and C#, but I hav ebeen programing in other languages and done some COM work for a number of years. I am attempting to understand how to map an older program...
4
by: | last post by:
Hello Guys, I am using the validation controls to validate my data. But the problem is "The page is still being posted to server". I want to get rid of the round trips to server. Are there...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
6
by: Valerian John | last post by:
I have a ListBox webcontrol on an aspx page. Items are added to the ListBox using client-side code. However, when the page is posted back the items are missing/not available. (It is like the...
10
by: Ben | last post by:
Hi, I made an application in classic asp (reservation of books and video stuffs for students) and want to migrate to asp.net. The user has to chose a date, then pushung on a submit button. The...
3
by: Simon Brooke | last post by:
I've been doing XSL transforms, converting XML to HTML, server side since 2000. In those days, clients which could do the transformation client side didn't exist, so whether to transform...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.