• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Https post

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic