• 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

HttpURLConnection problem?????

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic