Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: what is the reason of " Server returned HTTP response code: 403" error

  1. #1
    Join Date
    Mar 2010
    Thanked 0 Times in 0 Posts

    Default what is the reason of " Server returned HTTP response code: 403" error

    Hi , this is my code and when I execute it it generates following errors what is wrong with it.


    package googleSearch;

    import java.io.IOException;
    import java.io.InputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.net.URLEncoder;

    public class linkDiscovery {

    private String query = "news agency";
    // private String collection = " site : Wikipedia.org";
    // private String searchItem = query+collection;
    private String searchEngine = "http://www.google.com";

    // to search the query in a nominated collection

    public void displayItems() throws IOException {

    URL url = new URL(searchEngine + "/search?hl=en&source=hp&q="+ URLEncoder.encode(query, "UTF-8")+ "&meta=&aq=f&aqi=g10&aql=&oq=&gs_rfai=");

    HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection();
    InputStream inputStream = httpConnection.getInputStream();

    int ch;
    while ((ch=inputStream.read()) > 0) {

    public static void main(String[] args) throws IOException {
    new linkDiscovery().displayItems();



    Exception in thread "main" java.io.IOException: Server returned HTTP response code: 403 for URL: news agency - Google Search
    at sun.net.http://www.protocol.http.HttpURLConn...Stream(Unknown Source)
    at googleSearch.linkDiscovery.displayItems(linkDiscov ery.java:28)
    at googleSearch.linkDiscovery.main(linkDiscovery.java :38)

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default Re: what is the reason of " Server returned HTTP response code: 403" error

    See HTTP/1.1: Status Code Definitions

    In another Thread I alluded to how one can try and resolve this issue - but in that other thread I also alluded to perhaps violating google's terms of use in doing so (something you do not want to do).

  3. The Following User Says Thank You to copeg For This Useful Post:

    nasi (April 1st, 2010)

Similar Threads

  1. Replies: 1
    Last Post: January 15th, 2010, 01:32 AM
  2. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM
  3. Replies: 2
    Last Post: October 29th, 2009, 06:13 PM
  4. Getting "AWT-EventQueue-0" java.lang.NullPointerException error
    By tryingtoJava in forum AWT / Java Swing
    Replies: 9
    Last Post: September 21st, 2009, 10:46 PM
  5. Replies: 4
    Last Post: June 18th, 2009, 09:23 AM

Tags for this Thread