com.qq.connect.utils.json
类 HTTP

java.lang.Object
  继承者 com.qq.connect.utils.json.HTTP

public class HTTP
extends java.lang.Object

Convert an HTTP header to a JSONObject and back.


字段摘要
static java.lang.String CRLF
          Carriage return/line feed.
 
构造方法摘要
HTTP()
           
 
方法摘要
static JSONObject toJSONObject(java.lang.String string)
          Convert an HTTP header string into a JSONObject.
static java.lang.String toString(JSONObject o)
          Convert a JSONObject into an HTTP header.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

CRLF

public static final java.lang.String CRLF
Carriage return/line feed.

另请参见:
常量字段值
构造方法详细信息

HTTP

public HTTP()
方法详细信息

toJSONObject

public static JSONObject toJSONObject(java.lang.String string)
                               throws JSONException
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.

参数:
string - An HTTP header string.
返回:
A JSONObject containing the elements and attributes of the XML string.
抛出:
JSONException

toString

public static java.lang.String toString(JSONObject o)
                                 throws JSONException
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.

参数:
o - A JSONObject
返回:
An HTTP header string.
抛出:
JSONException - if the object does not contain enough information.