Node Director
Static Public Member Functions | Static Public Attributes | List of all members
org.json.HTTP Class Reference

Convert an HTTP header to a JSONObject and back. More...

Static Public Member Functions

static JSONObject toJSONObject (String string) throws ParseException
 Convert an HTTP header string into a JSONObject.
static String toString (JSONObject o) throws NoSuchElementException
 Convert a JSONObject into an HTTP header.

Static Public Attributes

static final String CRLF = "\r\n"
 Carriage return/line feed.

Detailed Description

Convert an HTTP header to a JSONObject and back.

Author
JSON.org
Version
0.1

Member Function Documentation

static JSONObject org.json.HTTP.toJSONObject ( String  string) throws ParseException
static

Convert an HTTP header string into a JSONObject.

It can be a request header or a response header. A request header will contain

{
   Method: "POST" (for example),
   "Request-URI": "/" (for example),
   "HTTP-Version": "HTTP/1.1" (for example)
}

A response header will contain

{
   "HTTP-Version": "HTTP/1.1" (for example),
   "Status-Code": "200" (for example),
   "Reason-Phrase": "OK" (for example)
}

In addition, the other parameters in the header will be captured, using the HTTP field names as JSON names, so that

   Date: Sun, 26 May 2002 18:06:04 GMT
   Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
   Cache-Control: no-cache

become

{...
   Date: "Sun, 26 May 2002 18:06:04 GMT",
   Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
   "Cache-Control": "no-cache",
...}

It does no further checking or conversion. It does not parse dates. It does not do '' transforms on URLs.

Parameters
stringAn HTTP header string.
Returns
A JSONObject containing the elements and attributes of the XML string.
Exceptions
ParseException

References org.json.JSONTokener.more(), org.json.JSONTokener.next(), org.json.JSONTokener.nextTo(), org.json.HTTPTokener.nextToken(), and org.json.JSONObject.put().

Referenced by org.json.Test.main().

static String org.json.HTTP.toString ( JSONObject  o) throws NoSuchElementException
static

Convert a JSONObject into an HTTP header.

A request header must contain

{
   Method: "POST" (for example),
   "Request-URI": "/" (for example),
   "HTTP-Version": "HTTP/1.1" (for example)
}

A response header must contain

{
   "HTTP-Version": "HTTP/1.1" (for example),
   "Status-Code": "200" (for example),
   "Reason-Phrase": "OK" (for example)
}

Any other members of the JSONObject will be output as HTTP fields. The result will end with two CRLF pairs.

Parameters
oA JSONObject
Returns
An HTTP header string.
Exceptions
NoSuchElementExceptionif the object does not contain enough information.

References org.json.HTTP.CRLF.

Referenced by org.json.Test.main().

Member Data Documentation

final String org.json.HTTP.CRLF = "\r\n"
static

Carriage return/line feed.

Referenced by org.json.HTTP.toString().


The documentation for this class was generated from the following file: