• Post Reply Bookmark Topic Watch Topic
  • New Topic

HttpURLConnection problem?????  RSS feed

 
Hemant KS Sengar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All!!
I was trying to get response code and response message from the server by writing this very small code... but I dont know where I'm making mistake because it is giving UnknownHostException.
Though for all other methods it is working fine except
getResponseCode() and getResponseMessage() methods.
Code goes here:
-------------------
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class SourceViewer {
public static void main(String[] args){

try{
URL u = new URL("http://www.amnesty.org/");
HttpURLConnection uc = (HttpURLConnection) u.openConnection();
int code = uc.getResponseCode();
System.out.println("HTTP 1.x"+code);
}
catch(IOException e){
e.printStackTrace();
System.err.println(e);
}
}
}
-------------
Thanks in advance.........
Hemant
 
Matt Siegel
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Worked fine for me. I got this:
HTTP 1.x 200
If you are getting an UnknownHostException, it seems like it is a DNS problem.
Matt
 
Hemant KS Sengar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Matt!
Thanks for your prompt reply. Actually I access Internet through Dial-up connection to my college server ...is this the reason(DHCP). Is there any way to get it solved....
Thanks
 
Ganapathi Srinivasan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hemant..
Try these things...
1. try giving the IP address instead of the url...
2. check whether u r behind a proxy server..if u r then change the system property of Httpproxyhost and Httpproxyport (am not sure of the exact spelling) to ur proxy server's ip and port and then run the code.
Regards,
Ganp.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!