Dear all,

I'm trying to download the page www.excite.com.

I made the class excite.java, listed below, and the server reports
the error HTTP/1.0 414 Request-URI Too Long. The class excite.java uses
the Java HttpURLConnection class.

I made another class, named excitesocket.java, listed below too. And I
get the expected response through it.

Please, could you help me find the error in the excite.java class ??? This
is very urgent and I already tried everything I know.

Thank you very much for your help !

Claudine

==============================================================

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

public class excite
{
    public static void main(String[] args) throws IOException
    {

        URL myURL = new URL("http://www.excite.com/");

        HttpURLConnection con = (HttpURLConnection)
myURL.openConnection();
        con.setRequestMethod("GET");
        con.setDoInput(true);

        con.setRequestProperty("Proxy-Connection", "Keep-Alive");
        con.setRequestProperty("Host" ,"search.excite.com");
        con.setRequestProperty("User-agent", "Mozilla/4.7 [en] (X11; U;
Linux 2.2.12 i686)");
        con.setRequestProperty("Accept", "image/gif, image/x-xbitmap,
image/jpeg, image/pjpeg, image/png, */*");
        con.setRequestProperty("Accept-Language", "en");
        con.setRequestProperty("Accept-Charset", "iso-8859-1,*,utf-8");

        BufferedReader myIn = new BufferedReader(new
InputStreamReader(con.getInputStream()));
        String line = null;
        StringBuffer sb = new StringBuffer();

        while ((line = myIn.readLine()) != null)
        {
            sb.append(line + "\n");
        }


        Integer RC = new Integer(con.getResponseCode());
        String ResponseCode = RC.toString();

        String ResponseMessage = con.getResponseMessage();

        System.out.println("Response Code:" + ResponseCode);
        System.out.println("Response Message:" + ResponseMessage);

        myIn.close();
        con.disconnect();
        System.out.println(sb.toString());
    }
}

=========================================================

public class excitesocket
{
    public static void main(String[] args) throws IOException
    {

        System.out.println("Trying to connect ...");

        Socket s = new Socket("www.excite.com",80);

        if (s!=null) System.out.println("Conectado!");

        DataOutputStream os = new DataOutputStream(s.getOutputStream());
        BufferedReader is = new BufferedReader(new
InputStreamReader(s.getInputStream()));

        /* Requisicao via GET */

        os.writeBytes("GET / HTTP/1.0\r\n");

        os.writeBytes("Proxy-Connection: Keep-Alive\r\n");
        os.writeBytes("User-Agent: Mozilla/4.7 [en] (X11; U; Linux 2.2.12
i686)\r\n");
        os.writeBytes("Host: www.excite.com\r\n");
        os.writeBytes("Accept: image/gif, image/x-xbitmap, image/jpeg,
image/pjpeg, image/png, */*\r\n");

        os.writeBytes("Accept-Language: en\r\n");
        os.writeBytes("Accept-Charset: iso-8859-1,*,utf-8\r\n\r\n");

        String line="";
        String response="";
        while ((line = is.readLine()) != null)
        {
            response += line + "\n";
        }

        System.out.print(response);

        is.close();
        os.close();
    }
}




***********************************************************************
*                       CLAUDINE SANTOS BADUE                         *
*                                                                     *
*                   Msc. Student - Computer Science                   *
* Laboratory for Treating Information (http://www.dcc.ufmg.br/latin/) *
*                         DCC - UFMG - Brazil                         *
***********************************************************************
* "For God so loved the world that He gave His one and only Son,      *
*  that whoever believes in Him shall not perish but have             *
*  eternal life" (John 3:16)                                          *
*                                                                     *
*  "Jesus answered: I am the way and the truth and the life.          *
*  No one comes to the Father except through me" (John 14:6)          *
***********************************************************************

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to