Java HTTP/S Component
The HTTP component provides an easy to use API for communicating
with an HTTP server. Written using 100% Java and delivered as a
Java Bean makes the HTTP component usable in a wide variety of IDE
and platform configurations. Download
Secure iNet Factory Evaluation
Features
- GET, POST and PUT support - Full support for GET, POST and
PUT operations emulating all the core functionality of a typical
web browser.
- SSL support - Access secure web pages using HTTPS (SSL)
- File upload support - Easily upload files to a web server
for processing by a CGI or servlet.
- Parameter management - Simple API allows easy addition or
removal of CGI name/value parameters from a HTTP request.
- Basic authentication - Provides methods for retrieving HTTP
documents which require a user supplied username and password.
- Cookie management - Add cookie values to a HTTP request, as
well as retrieve cookie data from a HTTP response.
- Header management - Easily define HTTP request header values
for submission with a HTTP request or retrieve header values
from a HTTP response.
- Proxy support - Provides methods for retrieving HTTP documents
from behind a firewall.
Code Example
The following example demonstrates how to retrieve the contents
of a web page from an HTTP server.
/*
* @(#)HttpExample.java
*
* Copyright (c) 2001-2002 JScape
* 1147 S. 53rd Pl., Mesa, Arizona, 85206, U.S.A.
* All rights reserved.
*
* This software is the confidential and proprietary information of
* JScape. ("Confidential Information"). You shall not disclose such
* Confidential Information and shall use it only in accordance with
* the terms of the license agreement you entered into with JScape.
*/
import com.jscape.inet.http.*;
import com.jscape.inet.mime.MimeException;
import java.io.*;
public class HttpExample extends HttpAdapter {
private String url;
public HttpExample(String url) {
this.url = url;
}
// print out contents of URL
public void getUrl() throws HttpException, MimeException {
// create new Http instance
Http http = new Http();
// register this class to capture HTTP related events
http.addHttpListener(this);
// create HTTP request
HttpRequest request = new HttpRequest(url,"GET");
// get HTTP response and print body to console
HttpResponse response = http.getResponse(request);
System.out.println(response.getBody());
}
public void connected(HttpConnectedEvent evt) {
System.out.println("Connected to: " + evt.getURL());
}
public void disconnected(HttpDisconnectedEvent evt) {
System.out.println("Disconnected from: " + evt.getURL());
}
public static void main(String[] args) {
String url;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter web address to retrieve (e.g. http://www.yahoo.com): ");
url = reader.readLine();
HttpExample example = new HttpExample(url);
example.getUrl();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
|
|