QHttpHeader Class Reference

[QtNetwork module]

该QHttpHeader类包含HTTP头信息。More…

通过继承QHttpRequestHeaderQHttpResponseHeader

Methods

  • __init__ (self)
  • __init__ (self, QHttpHeader header)
  • __init__ (self, QString str)
  • addValue (self, QString key, QString value)
  • QStringList allValues (self, QString key)
  • int contentLength (self)
  • QString contentType (self)
  • bool hasContentLength (self)
  • bool hasContentType (self)
  • bool hasKey (self, QString key)
  • bool isValid (self)
  • QStringList keys (self)
  • int majorVersion (self)
  • int minorVersion (self)
  • bool parse (self, QString str)
  • bool parseLine (self, QString line, int number)
  • removeAllValues (self, QString key)
  • removeValue (self, QString key)
  • setContentLength (self, int len)
  • setContentType (self, QString type)
  • setValid (self, bool)
  • setValue (self, QString key, QString value)
  • setValues (self, list-of-tuple-of-QString-QString values)
  • QString toString (self)
  • QString value (self, QString key)
  • list-of-tuple-of-QString-QString values (self)

Detailed Description

该QHttpHeader类包含HTTP头信息。

在大多数情况下,你应该使用这个类的更专业的衍生物,QHttpResponseHeaderQHttpRequestHeader,而不是直接使用QHttpHeader 。

QHttpHeader提供的HTTP标头字段。 HTTP头域由一个名称,后跟一个冒号,一个空格,和字段值。 (参见RFC 1945 )。字段名不区分大小写。一个典型的标头栏位看起来像这样:

  1. content-type: text/html

在API的报头字段的名称被称为“键”和内容被称为“价值” 。您可以获取和设置一个报头字段的值,用其与关键value()和setValue( ),例如

  1. header.setValue("content-type", "text/html");
  2. [QString]($docs-qstring.html) contentType = header.value("content-type");

有些领域是如此普遍, getter和setter方法​​是为他们提供一个方便的替代品使用value()和setValue( ),例如contentLength()和contentType( )setContentLength()和setContentType( ) 。

每头键都有一个single与它相关联的值。如果设置的值已经存在一个关键的前一个值将被丢弃。


Method Documentation

  1. QHttpHeader.__init__ (self)

构造一个空的HTTP标头。

  1. QHttpHeader.__init__ (self, QHttpHeader header)

构造的副本header

  1. QHttpHeader.__init__ (self, QString str)

构造一个HTTP头的str

这个构造函数解析字符串str为报头字段,并添加该信息。该str应该由一个或多个的“ \ r \ n ”分隔行;这些线路的格式应为关键,冒号,空格,值。

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

添加一个新条目与keyvalue

  1. QStringList QHttpHeader.allValues (self, QString key)

返回与给定的所有条目key。如果没有条目有这key,则返回一个空字符串列表。

  1. int QHttpHeader.contentLength (self)

返回特殊的HTTP标头字段的值content-length

See also setContentLength()和hasContentLength( ) 。

  1. QString QHttpHeader.contentType (self)

返回特殊的HTTP标头字段的值content-type

See also setContentType()和hasContentType( ) 。

  1. bool QHttpHeader.hasContentLength (self)

如果头具有特殊的HTTP标头字段中的条目,则返回Truecontent-length否则返回False 。

See also contentLength()和setContentLength( ) 。

  1. bool QHttpHeader.hasContentType (self)

如果头具有特殊的HTTP标头字段中的条目,则返回Truecontent-type否则返回False 。

See also contentType()和setContentType( ) 。

  1. bool QHttpHeader.hasKey (self, QString key)

如果HTTP头有一个给定的条目,则返回Truekey否则返回False 。

See also value( )setValue()和keys( ) 。

  1. bool QHttpHeader.isValid (self)

返回True如果HTTP头是有效的,否则返回False 。

A QHttpHeader是无效的,如果它是通过解析一个格式错误的字符串创建的。

  1. QStringList QHttpHeader.keys (self)

返回在HTTP报头中的键的列表。

See also hasKey( ) 。

  1. int QHttpHeader.majorVersion (self)

这种方法是抽象的,应在任何子类中重新实现。

返回主协议版本的HTTP标头。

  1. int QHttpHeader.minorVersion (self)

这种方法是抽象的,应在任何子类中重新实现。

返回未成年协议版本的HTTP标头。

  1. bool QHttpHeader.parse (self, QString str)
  1. bool QHttpHeader.parseLine (self, QString line, int number)
  1. QHttpHeader.removeAllValues (self, QString key)

删除与该键中的所有条目key从HTTP标头。

  1. QHttpHeader.removeValue (self, QString key)

删除与该键的条目key从HTTP标头。

See also value()和setValue( ) 。

  1. QHttpHeader.setContentLength (self, int len)

设置特殊的HTTP标头字段的值content-lengthlen

See also contentLength()和hasContentLength( ) 。

  1. QHttpHeader.setContentType (self, QString type)

设置特殊的HTTP标头字段的值content-typetype

See also contentType()和hasContentType( ) 。

  1. QHttpHeader.setValid (self, bool)
  1. QHttpHeader.setValue (self, QString key, QString value)

设置与该项目的值keyvalue

如果没有条目key存在,一个新的项与给定keyvalue被创建。如果与一个条目key已经存在,则第一个值将被丢弃并用给定的替换value

See also value( )hasKey()和removeValue( ) 。

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

套头项是在键值对列表values

See also values( ) 。

  1. QString QHttpHeader.toString (self)

返回的HTTP标头的字符串表示形式。

该字符串是适合于采用一个构造函数使用QString。它是由线的格式:关键,冒号,空格,值, “ \ r \ N” 。

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

返回与给定条目中的第一个值key。如果没有条目有这key,则返回一个空字符串。

See also setValue( )removeValue( )hasKey()和keys( ) 。

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

返回头中的所有条目。

See also setValues( ) 。