ccc.commons
Class HTTP

java.lang.Object
  extended by ccc.commons.HTTP

public final class HTTP
extends java.lang.Object

A simple library for making HTTP requests.

Author:
Civic Computing Ltd.

Method Summary
static java.lang.String decode(java.lang.String string, java.lang.String charset)
          Decode a string encoded with the application/x-www-form-urlencoded format.
static MimeType determineMimetype(java.lang.String filename)
          Guess the mime type of a file from its name.
static java.lang.String encode(java.lang.String string, java.lang.String charset)
          Encode a string using the application/x-www-form-urlencoded format.
static java.lang.String get(java.lang.String host, java.util.Map<java.lang.String,java.lang.String> params)
          Perform an HTTP GET.
static java.lang.String post(java.lang.String host, java.lang.String body, MimeType mimeType)
          Perform an HTTP POST.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

get

public static java.lang.String get(java.lang.String host,
                                   java.util.Map<java.lang.String,java.lang.String> params)
Perform an HTTP GET.

Parameters:
host - The host to GET from.
params - The request query parameters.
Returns:
The response body as a string.

post

public static java.lang.String post(java.lang.String host,
                                    java.lang.String body,
                                    MimeType mimeType)
Perform an HTTP POST.

Parameters:
host - The host to POST to.
body - The request body.
mimeType - The body's mime-type.
Returns:
The response body as a string.

encode

public static java.lang.String encode(java.lang.String string,
                                      java.lang.String charset)
Encode a string using the application/x-www-form-urlencoded format.

Parameters:
string - The string to encode.
charset - The charset used to generate encoded values.
Returns:
The encoded string.

decode

public static java.lang.String decode(java.lang.String string,
                                      java.lang.String charset)
Decode a string encoded with the application/x-www-form-urlencoded format.

Parameters:
string - The string to decode.
charset - The charset used to interpret encoded values.
Returns:
The decoded string.

determineMimetype

public static MimeType determineMimetype(java.lang.String filename)
Guess the mime type of a file from its name.

Parameters:
filename - The name of the file.
Returns:
The corresponding mime type.


Copyright © 2010. All Rights Reserved.