You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2005/04/08 00:57:22 UTC
svn commit: r160489 - in jakarta/httpclient/trunk/http-common/src/examples:
./ org/ org/apache/ org/apache/http/ org/apache/http/examples/
org/apache/http/examples/ElementalHttpGet.java
Author: olegk
Date: Thu Apr 7 15:57:22 2005
New Revision: 160489
URL: http://svn.apache.org/viewcvs?view=rev&rev=160489
Log:
HTTP GET demo using the most basic components
Added:
jakarta/httpclient/trunk/http-common/src/examples/
jakarta/httpclient/trunk/http-common/src/examples/org/
jakarta/httpclient/trunk/http-common/src/examples/org/apache/
jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/
jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/
jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java (with props)
Added: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java?view=auto&rev=160489
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java (added)
+++ jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java Thu Apr 7 15:57:22 2005
@@ -0,0 +1,90 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.examples;
+
+import org.apache.http.Header;
+import org.apache.http.HttpClientConnection;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
+import org.apache.http.entity.EntityConsumer;
+import org.apache.http.impl.DefaultHttpClientConnection;
+import org.apache.http.impl.DefaultHttpParams;
+import org.apache.http.impl.HttpGetRequest;
+import org.apache.http.params.HttpParams;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ */
+public class ElementalHttpGet {
+
+ public static void main(String[] args) throws Exception {
+
+ HttpParams connparams = new DefaultHttpParams(null);
+ HttpHost host = new HttpHost("www.yahoo.com");
+ HttpClientConnection conn = new DefaultHttpClientConnection();
+ try {
+
+ String[] targets = {
+ "/",
+ "/news/",
+ "/somewhere%20in%20pampa"};
+
+ for (int i = 0; i < targets.length; i++) {
+ HttpGetRequest request = new HttpGetRequest(targets[i]);
+ request.setHeader(new Header("Host", host.toHostString()));
+ request.setHeader(new Header("Agent", "Elemental HTTP client"));
+ request.setHeader(new Header("Connection", "Keep-Alive"));
+ if (!conn.isOpen()) {
+ System.out.println("Open new connection to: " + host);
+ conn.open(host, connparams, null);
+ } else {
+ System.out.println("Connection kept alive. Reusing...");
+ }
+ System.out.println(">> Request URI: " + request.getRequestLine().getUri());
+ HttpResponse response = conn.sendRequest(request);
+ if (response == null) {
+ response = conn.receiveResponse(request);
+ }
+ EntityConsumer body = new EntityConsumer(response);
+ System.out.println("<< Response: " + response.getStatusLine());
+ System.out.println(body.asString());
+ System.out.println("==============");
+ }
+ } finally {
+ conn.close();
+ }
+
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpGet.java
------------------------------------------------------------------------------
svn:mime-type = text/plain