QHttpHeader Class

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

頭: #include <QHttpHeader>
繼承者: QHttpRequestHeader and QHttpResponseHeader

該類已過時。 提供它是為使舊源代碼能繼續工作。強烈建議不要在新代碼中使用它。

公共函數

QHttpHeader ()
QHttpHeader (const QHttpHeader & header )
QHttpHeader (const QString & str )
virtual ~QHttpHeader ()
void addValue (const QString & key , const QString & value )
QStringList allValues (const QString & key ) const
uint contentLength () const
QString contentType () const
bool hasContentLength () const
bool hasContentType () const
bool hasKey (const QString & key ) const
bool isValid () const
QStringList keys () const
virtual int majorVersion () const = 0
virtual int minorVersion () const = 0
void removeAllValues (const QString & key )
void removeValue (const QString & key )
void setContentLength (int len )
void setContentType (const QString & type )
void setValue (const QString & key , const QString & value )
void setValues (const QList<QPair<QString, QString> > & values )
virtual QString toString () const
QString value (const QString & key ) const
QList<QPair<QString, QString> > values () const
QHttpHeader & operator= (const QHttpHeader & h )

詳細描述

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.

另請參閱 QHttpRequestHeader and QHttpResponseHeader .

成員函數文檔編製

QHttpHeader:: QHttpHeader ()

Constructs an empty HTTP header.

QHttpHeader:: QHttpHeader (const QHttpHeader & header )

構造副本為 header .

QHttpHeader:: QHttpHeader (const 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:: ~QHttpHeader ()

析構函數。

void QHttpHeader:: addValue (const QString & key , const QString & value )

Adds a new entry with the key and value .

QStringList QHttpHeader:: allValues (const QString & key ) const

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

uint QHttpHeader:: contentLength () const

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

另請參閱 setContentLength () 和 hasContentLength ().

QString QHttpHeader:: contentType () const

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

另請參閱 setContentType () 和 hasContentType ().

bool QHttpHeader:: hasContentLength () const

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

另請參閱 contentLength () 和 setContentLength ().

bool QHttpHeader:: hasContentType () const

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

另請參閱 contentType () 和 setContentType ().

bool QHttpHeader:: hasKey (const QString & key ) const

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

另請參閱 value (), setValue (),和 keys ().

bool QHttpHeader:: isValid () const

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 () const

Returns a list of the keys in the HTTP header.

另請參閱 hasKey ().

[pure virtual] int QHttpHeader:: majorVersion () const

Returns the major protocol-version of the HTTP header.

[pure virtual] int QHttpHeader:: minorVersion () const

Returns the minor protocol-version of the HTTP header.

void QHttpHeader:: removeAllValues (const QString & key )

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

void QHttpHeader:: removeValue (const QString & key )

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

另請參閱 value () 和 setValue ().

void QHttpHeader:: setContentLength ( int len )

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

另請參閱 contentLength () 和 hasContentLength ().

void QHttpHeader:: setContentType (const QString & type )

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

另請參閱 contentType () 和 hasContentType ().

void QHttpHeader:: setValue (const QString & key , const 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 ().

void QHttpHeader:: setValues (const QList < QPair < QString , QString > > & values )

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

另請參閱 values ().

[虛擬] QString QHttpHeader:: toString () const

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 (const QString & key ) const

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 ().

QList < QPair < QString , QString > > QHttpHeader:: values () const

Returns all the entries in the header.

另請參閱 setValues ().

QHttpHeader & QHttpHeader:: operator= (const QHttpHeader & h )

賦值 h and returns a reference to this http header.