QHttpHeader Class Reference

[ QtNetwork module]

The QHttpHeader class contains header information for HTTP. 更多...

Inherited by QHttpRequestHeader and QHttpResponseHeader .

方法


详细描述

The QHttpHeader class contains header information for HTTP.

In most cases you should use the more specialized derivatives of this class, QHttpResponseHeader and QHttpRequestHeader , rather than directly using QHttpHeader.

QHttpHeader provides the HTTP header fields. A HTTP header field consists of a name followed by a colon, a single space, and the field value. (See RFC 1945.) Field names are case-insensitive. A typical header field looks like this:

 content-type: text/html
			

In the API the header field name is called the "key" and the content is called the "value". You can get and set a header field's value by using its key with value () 和 setValue (),如

 header.setValue("content-type", "text/html");
 QString contentType = header.value("content-type");
			

Some fields are so common that getters and setters are provided for them as a convenient alternative to using value () 和 setValue (),如 contentLength () 和 contentType (), setContentLength () 和 setContentType ().

Each header key has a single value associated with it. If you set the value for a key which already exists the previous value will be discarded.


方法文档编制

QHttpHeader.__init__ ( self )

Constructs an empty HTTP header.

QHttpHeader.__init__ ( self , QHttpHeader   header )

构造副本为 header .

QHttpHeader.__init__ ( self , QString  str )

Constructs a HTTP header for str .

This constructor parses the string str for header fields and adds this information. The str should consist of one or more "\r\n" delimited lines; each of these lines should have the format key, colon, space, value.

QHttpHeader.addValue ( self , QString  key , QString  value )

Adds a new entry with the key and value .

QStringList QHttpHeader.allValues ( self , QString  key )

Returns all the entries with the given key . If no entry has this key , an empty string list is returned.

int QHttpHeader.contentLength ( self )

Returns the value of the special HTTP header field content-length .

另请参阅 setContentLength () 和 hasContentLength ().

QString QHttpHeader.contentType ( self )

Returns the value of the special HTTP header field content-type .

另请参阅 setContentType () 和 hasContentType ().

bool QHttpHeader.hasContentLength ( self )

Returns true if the header has an entry for the special HTTP header field content-length ;否则返回 false。

另请参阅 contentLength () 和 setContentLength ().

bool QHttpHeader.hasContentType ( self )

Returns true if the header has an entry for the special HTTP header field content-type ;否则返回 false。

另请参阅 contentType () 和 setContentType ().

bool QHttpHeader.hasKey ( self , QString  key )

Returns true if the HTTP header has an entry with the given key ;否则返回 false。

另请参阅 value (), setValue (),和 keys ().

bool QHttpHeader.isValid ( self )

Returns true if the HTTP header is valid; otherwise returns false.

A QHttpHeader is invalid if it was created by parsing a malformed string.

QStringList QHttpHeader.keys ( self )

Returns a list of the keys in the HTTP header.

另请参阅 hasKey ().

int QHttpHeader.majorVersion ( self )

This method is abstract and should be reimplemented in any sub-class.

Returns the major protocol-version of the HTTP header.

int QHttpHeader.minorVersion ( self )

This method is abstract and should be reimplemented in any sub-class.

Returns the minor protocol-version of the HTTP header.

bool QHttpHeader.parse ( self , QString  str )

bool QHttpHeader.parseLine ( self , QString  line , int  number )

QHttpHeader.removeAllValues ( self , QString  key )

Removes all the entries with the key key from the HTTP header.

QHttpHeader.removeValue ( self , QString  key )

Removes the entry with the key key from the HTTP header.

另请参阅 value () 和 setValue ().

QHttpHeader.setContentLength ( self , int  len )

Sets the value of the special HTTP header field content-length to len .

另请参阅 contentLength () 和 hasContentLength ().

QHttpHeader.setContentType ( self , QString  type )

Sets the value of the special HTTP header field content-type to type .

另请参阅 contentType () 和 hasContentType ().

QHttpHeader.setValid ( self , bool)

QHttpHeader.setValue ( self , QString  key , QString  value )

Sets the value of the entry with the key to value .

If no entry with key exists, a new entry with the given key and value is created. If an entry with the key already exists, the first value is discarded and replaced with the given value .

另请参阅 value (), hasKey (),和 removeValue ().

QHttpHeader.setValues ( self , list-of-tuple-of-QString-QString  values )

Sets the header entries to be the list of key value pairs in values .

另请参阅 values ().

QString QHttpHeader.toString ( self )

Returns a string representation of the HTTP header.

The string is suitable for use by the constructor that takes a QString . It consists of lines with the format: key, colon, space, value, "\r\n".

QString QHttpHeader.value ( self , QString  key )

Returns the first value for the entry with the given key . If no entry has this key , an empty string is returned.

另请参阅 setValue (), removeValue (), hasKey (),和 keys ().

list-of-tuple-of-QString-QString QHttpHeader.values ( self )

Returns all the entries in the header.

另请参阅 setValues ().