• Post Reply Bookmark Topic Watch Topic
  • New Topic

URL and Socket objects from IP address  RSS feed

 
Reddy Kurli
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to connect to an https URL address of the form: "ip_address/file_path/file_name" using URL object and Socket objects. I have tried creating URL objects from this available data but none of the URL constructors take IP address. I have tried using the IP address in the place of "host" parameter but I keep getting "java.net.UnknownHostException". Similarly when I created socket:
SocketFactory.getDefault().createSocket("IP_address/file_path/file_name",port) I once again get the "java.net.UnknownHostException".
Also when I enter just the IP address without any file path or path name, I get an error message saying the IP address should be entered in the form <IP address>
i.e within angle brackets. The hostname/domain name is not published by the vendor.
Can someone please point me in the right direction as to what I might be missing.
Thanks in advance.
Regards,
Raza
Below is the sample of code I am working on:
// Get a socket factory
//SocketFactory factory = SSLSocketFactory.getDefault();
// Get a socket from factory
/*Socket socket = factory.createSocket("65.216.120.46/secure/Pxapi.asp",HTTPS_PORT);

writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

writer.write(login);
writer.flush(); */

//adstar = new URL("https://secure.authorize.net/gateway/transact.dll"); this works
adstar = new URL(https://65.216.120.46/secure/Pxapi.asp);
urlConnection = adstar.openConnection();
urlConnection.setDoOutput(true);
out = new PrintWriter(urlConnection.getOutputStream());
//out.println(login);
reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
//}

String line = null;
StringBuffer sb = new StringBuffer();

while((line = reader.readLine()) != null) {
sb.append(line);
}
//writer.close();
reader.close();
System.out.println(sb.toString());

//out.println(command);
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does that sample really work with HTTPS on it? I had to do some special stuff with my URL to connect to HTTPS.
The address that doesn't work for you ... does it work if you type it in a browser? This address will have to be a web server that understands HTTP.
 
Reddy Kurli
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the code works fine for other https sites as long as it is in xxx.xxx.xxx.xxx or www.hostname.com format but once I append the file path and file name it does not seems to work and I get java.net.UnknowHostException.
And yes if I type the address it the browser it indeed access the web site.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!