This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Https connection using a hostname not a url.  RSS feed

 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to establish a https connection for which i will provide a hostname portno username password etc.
most of the online code snippets are mostly using SSl or TSL inorder to establish a connection if not using a url and establishing the connection by appending the encrypted username and password with it to establish a connection.

i have a scenario where i use a hostname portno(optional) username password and to establish the connection. can any one guide me how to do this.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried new URLConnection("https://www.server.com:1234")? It'll probably work out of the box. Passing the username/password has nothing to do with HTTP vs. HTTPS, so you need to do that independently of making the connection.
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply, can you explain a bit clear
Ulf Dittmer wrote:Have you tried new URLConnection("https://www.server.com:1234")?

i used SSLServerSocketFactory, SSLServerSocket & SSLSocket on the server side
SSLSocketFactory, SSLSocket on the client for a basic connection.

but my main question is to avoid a url and ssl(i guess cannot be ignored) ,completly use https connection to perform the communication, but
Ulf Dittmer wrote:URLConnection("https://www.server.com:1234")?

will answer my problem?
but if you have asked me whether https connection worked using the url then my answer is yes.
correct me if i am wrong in understanding what you have asked and i guess i made my requirement clear, please guide me.
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Have you tried new URLConnection("https://www.server.com:1234")? It'll probably work out of the box.

Not like this; URLConnection is abstract. Using java.net.URL it should work though:

Saipraneeth, a URL and host name do not need to be mutually exclusive. http://www.javaranch.com/ is a URL that has a host name; http://127.0.0.1/ is a URL that has an IP address.
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote: a URL and host name do not need to be mutually exclusive. http://www.javaranch.com/ is a URL that has a host name; http://127.0.0.1/ is a URL that has an IP address.

upto my knowledge the IP-address for machine in order to make it more simple to use undergoes DNS configuration which will get www.somename.com, correct me if i am wrong.
so here can say from your explanation that i can use the machine name that i am using as the hostname for the sake of the connection(secure)?
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the other way around - www.somename.com will be translated into an IP address. So if you use a host name in the URL, this is somewhere in the background (probably even outside your Java program) translated into an IP address, and a request is made to this IP address on the port you specified with the HTTPS protocol. So what makes your connection secure is not the host name, IP address or port, but the protocol.
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks RobPrime it did worked.
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!