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
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
Joined: Jul 14, 2006
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
Joined: Jul 14, 2006
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.