All pastes #22791 Raw Edit

Stuff

public java v1 · immutable
#22791 ·published 2005-09-13 07:48 UTC
rendered paste body
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Arrays;import javax.imageio.ImageIO;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.HttpException;import org.apache.commons.httpclient.HttpMethod;import org.apache.commons.httpclient.cookie.CookiePolicy;import org.apache.commons.httpclient.methods.GetMethod;/* * $Header: Site.java, 13/09/2005 15:58:26 luisantonioa Exp $ * * $Author: luisantonioa $ * $Date: 13/09/2005 15:58:26 $ * $Revision: 1 $ * $Log: Site.java,v $ * Revision 1  13/09/2005 15:58:26  luisantonioa * Added copyright notice * *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * http://www.gnu.org/copyleft/gpl.html *//** * This class ... *  * @version $Revision: 1.2 $ $Date: 2004/06/27 08:12:59 $ */public class Site{    public static void main(String[] args) throws HttpException, IOException    {        HttpClient client = new HttpClient();                GetMethod method = new GetMethod("http://www.l2wh.com/updrop/");        method.getParams().setCookiePolicy(CookiePolicy.RFC_2109);        method.setRequestHeader("Connection", "Keep-Alive");        method.setRequestHeader("Host", "www.l2wh.com");                client.executeMethod(method);                showHeaders(method);        //String tag = method.getResponseHeader("ETag").getValue();        //System.out.println("** "+method.getPath());/updrop/low.php                method.setPath("/updrop/nav.php");        method.setRequestHeader("Referer", "http://www.l2wh.com/updrop/");        client.executeMethod(method);        showHeaders(method);        showBody(method);                method.setPath("/updrop/low.php");        method.setRequestHeader("Referer", "http://www.l2wh.com/updrop/");        client.executeMethod(method);        showHeaders(method);        showBody(method);                method.setPath("/updrop/itemfind.php");        method.setRequestHeader("Referer", "http://www.l2wh.com/updrop/nav.php");        client.executeMethod(method);        showHeaders(method);        showBody(method);                method.setPath("/updrop/itemfind.php?itemid=856&l2wh=&ncr=1");        method.setRequestHeader("Referer", "http://www.l2wh.com/updrop/nav.php");        client.executeMethod(method);        showHeaders(method);        showBody(method);                method.setPath("/updrop/pic.php?id=a8d30501");        method.setRequestHeader("Referer", "http://www.l2wh.com/updrop/nav.php");        client.executeMethod(method);        showHeaders(method);        readPng(method);    }        /**     * @param method     */    private static void readPng(GetMethod method)    {           }    public static void showHeaders(HttpMethod method)    {        System.out.println("GET "+method.getPath());        System.out.println("Headers Sent");        System.out.println(Arrays.toString(method.getRequestHeaders()));        System.out.println();        System.out.println("Headers Received");        System.out.println(Arrays.toString(method.getResponseHeaders()));        System.out.println();    }        public static void showBody(HttpMethod method) throws IOException    {        System.out.println("Headers Received");        //System.out.println(method.getResponseBodyAsString());        BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));        String line = reader.readLine();        while (line != null)        {            System.out.println(line);            line = reader.readLine();        }    }}