URL and Socket Objects from IP Address

R

Raza Muzaffar

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",por
t) 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);
 
R

Raza Muzaffar

I checked the URL below but it did not mentioned the issue I am having. I am
getting java.net.UnknownHostException when I use the
https://xxx.xxx.xxx.xxx/file_path_file_name in the construction of URL
objects. None of the URL constructors accept the hostname in the above
mentioned form. Similarly I was getting the same error messages while using
the Socket approach.

Regards,
Raza
 
M

marcus

sure URL can take an IP address. This works:

import java.io.*;
import java.net.*;


public class whoami{
public static void main(String[] args) {

URL uu=null;
try{
uu = new URL("HTTP","66.167.170.58",80,"/index.html");
} catch(MalformedURLException e){System.out.println("bad URL");}
try{
URLConnection uc = uu.openConnection();
BufferedReader br = new BufferedReader(new
InputStreamReader(uc.getInputStream()));
System.out.println(br.readLine());
System.out.println(br.readLine());

} catch(IOException e){System.out.println("bad IO "+e);}
}


}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top