jQuery in Action, 3rd edition
The moose likes Sockets and Internet Protocols and the fly likes Https post Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Https post" Watch "Https post" New topic

Https post

Mark Hughes
Ranch Hand

Joined: Jul 14, 2006
Posts: 146
Hey guys
Im trying to make a post to a https web site,
basically im using the below code to do the http post which works for a http web site but not for a https web site. Can anybody shed some light on my problem as to why it would not work, i suspect due to security certificats or SSL layers or something. If some body has a link or code that works to make a https post that would be great too.

anyway heres the code i found for a normal http post

Best Mark
any help appreciated
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

If it's an HTTPS website, you need the SSL certificate. So you need to tell where your truststore and keystore are. Add these lines in your code.

You also need to import the SSL certificate into you truststore if it's not already inside.

SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
Mark Hughes
Ranch Hand

Joined: Jul 14, 2006
Posts: 146
cool thanks Freddy, appreciate your help.
Im just looking at the code, when im setting the system.properties there is a field called password, will i need to change that to something or is it ok the way is is?

also the import code syntax looks a bit different to me, copying and pasting it directly into eclipse throws an error, what do i need to do to get fix the syntax error. Sorry if that sounds like a silly question
Mark Hughes
Ranch Hand

Joined: Jul 14, 2006
Posts: 146
i tried running that code you gave me, and it throw the following exception

java.net.SocketException: Default SSL context init failed: null
at javax.net.ssl.DefaultSSLSocketFactory.createSocket(SSLSocketFactory.java:163)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:372)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:170)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:839)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
at org.test.https.httpstest.main(httpstest.java:53)

I basically set the system properties, than attempted the http post but the error was thrown straight away once i tried to open the connection.

Also on the import, is that done throw the command line or does it need to be done programmatically, if so how do i go about doing that.

Thanks again for your help
I agree. Here's the link: http://aspose.com/file-tools
subject: Https post
It's not a secret anymore!