⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qhttp.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    return hasKey(QLatin1String("content-type"));}/*!    Returns the value of the special HTTP header field \c content-type.    \sa setContentType() hasContentType()*/QString QHttpHeader::contentType() const{    QString type = value(QLatin1String("content-type"));    if (type.isEmpty())        return QString();    int pos = type.indexOf(QLatin1Char(';'));    if (pos == -1)        return type;    return type.left(pos).trimmed();}/*!    Sets the value of the special HTTP header field \c content-type to    \a type.    \sa contentType() hasContentType()*/void QHttpHeader::setContentType(const QString &type){    setValue(QLatin1String("content-type"), type);}class QHttpResponseHeaderPrivate : public QHttpHeaderPrivate{    Q_DECLARE_PUBLIC(QHttpResponseHeader)public:    int statCode;    QString reasonPhr;    int majVer;    int minVer;};/**************************************************** * * QHttpResponseHeader * ****************************************************//*!    \class QHttpResponseHeader    \brief The QHttpResponseHeader class contains response header information for HTTP.    \ingroup io    \module network    This class is used by the QHttp class to report the header    information that the client received from the server.    HTTP responses have a status code that indicates the status of the    response. This code is a 3-digit integer result code (for details    see to RFC 1945). In addition to the status code, you can also    specify a human-readable text that describes the reason for the    code ("reason phrase"). This class allows you to get the status    code and the reason phrase.    \sa QHttpRequestHeader, QHttp, {HTTP Example}*//*!    Constructs an empty HTTP response header.*/QHttpResponseHeader::QHttpResponseHeader()    : QHttpHeader(*new QHttpResponseHeaderPrivate){    setValid(false);}/*!    Constructs a copy of \a header.*/QHttpResponseHeader::QHttpResponseHeader(const QHttpResponseHeader &header)    : QHttpHeader(*new QHttpResponseHeaderPrivate, header){    Q_D(QHttpResponseHeader);    d->statCode = header.d_func()->statCode;    d->reasonPhr = header.d_func()->reasonPhr;    d->majVer = header.d_func()->majVer;    d->minVer = header.d_func()->minVer;}/*!    Copies the contents of \a header into this QHttpResponseHeader.*/QHttpResponseHeader &QHttpResponseHeader::operator=(const QHttpResponseHeader &header){    Q_D(QHttpResponseHeader);    QHttpHeader::operator=(header);    d->statCode = header.d_func()->statCode;    d->reasonPhr = header.d_func()->reasonPhr;    d->majVer = header.d_func()->majVer;    d->minVer = header.d_func()->minVer;    return *this;}/*!    Constructs a HTTP response header from the string \a str. The    string is parsed and the information is set. The \a str should    consist of one or more "\r\n" delimited lines; the first line should be the    status-line (format: HTTP-version, space, status-code, space,    reason-phrase); each of remaining lines should have the format key, colon,    space, value.*/QHttpResponseHeader::QHttpResponseHeader(const QString &str)    : QHttpHeader(*new QHttpResponseHeaderPrivate){    parse(str);}/*!    \since 4.1    Constructs a QHttpResponseHeader, setting the status code to \a code, the    reason phrase to \a text and the protocol-version to \a majorVer and \a    minorVer.    \sa statusCode() reasonPhrase() majorVersion() minorVersion()*/QHttpResponseHeader::QHttpResponseHeader(int code, const QString &text, int majorVer, int minorVer)    : QHttpHeader(*new QHttpResponseHeaderPrivate){    setStatusLine(code, text, majorVer, minorVer);}/*!    \since 4.1    Sets the status code to \a code, the reason phrase to \a text and    the protocol-version to \a majorVer and \a minorVer.    \sa statusCode() reasonPhrase() majorVersion() minorVersion()*/void QHttpResponseHeader::setStatusLine(int code, const QString &text, int majorVer, int minorVer){    Q_D(QHttpResponseHeader);    setValid(true);    d->statCode = code;    d->reasonPhr = text;    d->majVer = majorVer;    d->minVer = minorVer;}/*!    Returns the status code of the HTTP response header.    \sa reasonPhrase() majorVersion() minorVersion()*/int QHttpResponseHeader::statusCode() const{    Q_D(const QHttpResponseHeader);    return d->statCode;}/*!    Returns the reason phrase of the HTTP response header.    \sa statusCode() majorVersion() minorVersion()*/QString QHttpResponseHeader::reasonPhrase() const{    Q_D(const QHttpResponseHeader);    return d->reasonPhr;}/*!    Returns the major protocol-version of the HTTP response header.    \sa minorVersion() statusCode() reasonPhrase()*/int QHttpResponseHeader::majorVersion() const{    Q_D(const QHttpResponseHeader);    return d->majVer;}/*!    Returns the minor protocol-version of the HTTP response header.    \sa majorVersion() statusCode() reasonPhrase()*/int QHttpResponseHeader::minorVersion() const{    Q_D(const QHttpResponseHeader);    return d->minVer;}/*! \reimp*/bool QHttpResponseHeader::parseLine(const QString &line, int number){    Q_D(QHttpResponseHeader);    if (number != 0)        return QHttpHeader::parseLine(line, number);    QString l = line.simplified();    if (l.length() < 10)        return false;    if (l.left(5) == QLatin1String("HTTP/") && l[5].isDigit() && l[6] == QLatin1Char('.') &&        l[7].isDigit() && l[8] == QLatin1Char(' ') && l[9].isDigit()) {        d->majVer = l[5].toLatin1() - '0';        d->minVer = l[7].toLatin1() - '0';        int pos = l.indexOf(QLatin1Char(' '), 9);        if (pos != -1) {            d->reasonPhr = l.mid(pos + 1);            d->statCode = l.mid(9, pos - 9).toInt();        } else {            d->statCode = l.mid(9).toInt();            d->reasonPhr.clear();        }    } else {        return false;    }    return true;}/*! \reimp*/QString QHttpResponseHeader::toString() const{    Q_D(const QHttpResponseHeader);    QString ret(QLatin1String("HTTP/%1.%2 %3 %4\r\n%5\r\n"));    return ret.arg(d->majVer).arg(d->minVer).arg(d->statCode).arg(d->reasonPhr).arg(QHttpHeader::toString());}class QHttpRequestHeaderPrivate : public QHttpHeaderPrivate{    Q_DECLARE_PUBLIC(QHttpRequestHeader)public:    QString m;    QString p;    int majVer;    int minVer;};/**************************************************** * * QHttpRequestHeader * ****************************************************//*!    \class QHttpRequestHeader    \brief The QHttpRequestHeader class contains request header information for HTTP.    \ingroup io    \module network    This class is used in the QHttp class to report the header    information if the client requests something from the server.    HTTP requests have a method which describes the request's action.    The most common requests are "GET" and "POST". In addition to the    request method the header also includes a request-URI to specify    the location for the method to use.    The method, request-URI and protocol-version can be set using a    constructor or later using setRequest(). The values can be    obtained using method(), path(), majorVersion() and    minorVersion().    Important inherited functions: setValue() and value().    \sa QHttpResponseHeader QHttp*//*!    Constructs an empty HTTP request header.*/QHttpRequestHeader::QHttpRequestHeader()    : QHttpHeader(*new QHttpRequestHeaderPrivate){    setValid(false);}/*!    Constructs a HTTP request header for the method \a method, the    request-URI \a path and the protocol-version \a majorVer and \a minorVer.*/QHttpRequestHeader::QHttpRequestHeader(const QString &method, const QString &path, int majorVer, int minorVer)    : QHttpHeader(*new QHttpRequestHeaderPrivate){    Q_D(QHttpRequestHeader);    d->m = method;    d->p = path;    d->majVer = majorVer;    d->minVer = minorVer;}/*!    Constructs a copy of \a header.*/QHttpRequestHeader::QHttpRequestHeader(const QHttpRequestHeader &header)    : QHttpHeader(*new QHttpRequestHeaderPrivate, header){    Q_D(QHttpRequestHeader);    d->m = header.d_func()->m;    d->p = header.d_func()->p;    d->majVer = header.d_func()->majVer;    d->minVer = header.d_func()->minVer;}/*!    Copies the content of \a header into this QHttpRequestHeader*/QHttpRequestHeader &QHttpRequestHeader::operator=(const QHttpRequestHeader &header){    Q_D(QHttpRequestHeader);    QHttpHeader::operator=(header);    d->m = header.d_func()->m;    d->p = header.d_func()->p;    d->majVer = header.d_func()->majVer;    d->minVer = header.d_func()->minVer;    return *this;}/*!    Constructs a HTTP request header from the string \a str. The \a    str should consist of one or more "\r\n" delimited lines; the first line    should be the request-line (format: method, space, request-URI, space    HTTP-version); each of the remaining lines should have the format key,    colon, space, value.*/QHttpRequestHeader::QHttpRequestHeader(const QString &str)    : QHttpHeader(*new QHttpRequestHeaderPrivate){    parse(str);}/*!    This function sets the request method to \a method, the    request-URI to \a path and the protocol-version to \a majorVer and    \a minorVer.    \sa method() path() majorVersion() minorVersion()*/void QHttpRequestHeader::setRequest(const QString &method, const QString &path, int majorVer, int minorVer){    Q_D(QHttpRequestHeader);    setValid(true);    d->m = method;    d->p = path;    d->majVer = majorVer;    d->minVer = minorVer;}/*!    Returns the method of the HTTP request header.    \sa path() majorVersion() minorVersion() setRequest()*/QString QHttpRequestHeader::method() const{    Q_D(const QHttpRequestHeader);    return d->m;}/*!    Returns the request-URI of the HTTP request header.    \sa method() majorVersion() minorVersion() setRequest()*/QString QHttpRequestHeader::path() const{    Q_D(const QHttpRequestHeader);    return d->p;}/*!    Returns the major protocol-version of the HTTP request header.    \sa minorVersion() method() path() setRequest()*/int QHttpRequestHeader::majorVersion() const{    Q_D(const QHttpRequestHeader);    return d->majVer;}/*!    Returns the minor protocol-version of the HTTP request header.    \sa majorVersion() method() path() setRequest()*/int QHttpRequestHeader::minorVersion() const{    Q_D(const QHttpRequestHeader);    return d->minVer;}/*! \reimp*/bool QHttpRequestHeader::parseLine(const QString &line, int number){    Q_D(QHttpRequestHeader);    if (number != 0)        return QHttpHeader::parseLine(line, number);    QStringList lst = line.simplified().split(QLatin1String(" "));    if (lst.count() > 0) {        d->m = lst[0];        if (lst.count() > 1) {            d->p = lst[1];            if (lst.count() > 2) {                QString v = lst[2];                if (v.length() >= 8 && v.left(5) == QLatin1String("HTTP/") &&                    v[5].isDigit() && v[6] == QLatin1Char('.') && v[7].isDigit()) {                    d->majVer = v[5].toLatin1() - '0';                    d->minVer = v[7].toLatin1() - '0';                    return true;                }            }        }    }    return false;}/*! \reimp*/QString QHttpRequestHeader::toString() const{    Q_D(const QHttpRequestHeader);    QString first(QLatin1String("%1 %2"));    QString last(QLatin1String(" HTTP/%3.%4\r\n%5\r\n"));    return first.arg(d->m).arg(d->p) +        last.arg(d->majVer).arg(d->minVer).arg(QHttpHeader::toString());}/**************************************************** * * QHttp * ****************************************************//*!    \class QHttp    \reentrant    \brief The QHttp class provides an implementation of the HTTP protocol.    \ingroup io    \module network    \mainclass    This class provides a direct interface to HTTP that allows you to    have more control over the requests and that allows you to access    the response header fields.    The class works asynchronously, so there are no blocking    functions. If an operation cannot be executed immediately, the    function will still return straight away and the operation will be    scheduled for later execution. The results of scheduled operations

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -