Exemple #1
0
QString ImportIconsWizard::wget(QUrl& url,const QString& strParam )
{
    QByteArray raw(strParam.toAscii());
    QBuffer data(&raw);
    QHttpRequestHeader header;

    header.setContentType(QString("application/x-www-form-urlencoded"));
    header.setContentLength(raw.size());

    header.setValue("User-Agent", "MythTV Channel Icon lookup bot");

    QString str = HttpComms::postHttp(url,&header,&data);

    return str;
}
QString ImportIconsWizard::wget(QUrl& url,const QString& strParam )
{
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
    QByteArray raw(strParam.toLatin1());
    QBuffer data(&raw);
    QHttpRequestHeader header;

    header.setContentType(QString("application/x-www-form-urlencoded"));
    header.setContentLength(raw.size());

    header.setValue("User-Agent", "MythTV Channel Icon lookup bot");

    QString str = HttpComms::postHttp(url,&header,&data);

    return str;
#else
#warning ImportIconsWizard::wget() not ported to Qt5
    return QString();
#endif
}
Exemple #3
0
void
SmugMug::WebService::_uploadMultipartHttpPost (
    const QString &AlbumId,
    const QString &FileName,
    const QString &Caption) {

    const QString BOUNDARY = "----------ThIs_Is_tHe_bouNdaRY_$";
    const QString CFLF = "\r\n";

    QUrl url (UploadEndpoint + "/photos/xmladd.mg");

    _dataOut.clear ();

    QByteArray imageData;
    QFileInfo fi (FileName);
    QFile file (fi.absoluteFilePath ());
    if (file.open (QIODevice::ReadOnly)) {

        imageData = file.readAll ();
        file.close ();
    }

    // Album ID
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"AlbumID\"") + CFLF + CFLF;
    _dataOut += AlbumId + CFLF;

    // Session ID
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"SessionID\"") + CFLF + CFLF;
    _dataOut += _sessionId + CFLF;

    // Byte Count
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"ByteCount\"") + CFLF + CFLF;
    _dataOut += QString::number (imageData.length ()) + CFLF;

    // Response Type
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"ResponseType\"") + CFLF + CFLF;
    _dataOut += QString ("REST") + CFLF;

    // MD5 Sum
    _dataOut += QString ("--") + BOUNDARY + CFLF;
    _dataOut += QString ("Content-Disposition: form-data; name=\"MD5Sum\"") + CFLF + CFLF;
    _dataOut += md5_digest (imageData) + CFLF;
//   _dataOut += QString ("a234ab01efe2775e9f69477831c3d3ca") + CFLF;

    // Caption
    if (!Caption.isEmpty ()) {

        _dataOut += QString ("--") + BOUNDARY + CFLF;
        _dataOut += QString ("Content-Disposition: form-data; name=\"Caption\"") + CFLF + CFLF;
        _dataOut += Caption + CFLF;
    }

    // Add the file
    _dataOut += QString ("--") + BOUNDARY + CFLF;

    _dataOut += QString ("Content-Disposition: form-data; name=\"Image\"") +
                QString ("; filename=\"%1\"").arg (fi.fileName ()) + CFLF;

    _dataOut += QString ("Content-Type: image/jpeg") + CFLF;
    _dataOut += QString ("Content-length: %1").arg (imageData.length ()) + CFLF + CFLF;

    qDebug () << _dataOut;

    _dataOut += imageData;
    _dataOut += CFLF;

    _dataOut += QString ("--") + BOUNDARY + "--" + CFLF;

    QHttpRequestHeader header ("POST", url.path ());
    header.setValue ("Host", url.host ());
//   header.setValue ("Cookie", QString ("SMSESS=") + _sessionId);
    header.setContentType (QString ("multipart/form-data; boundary=") + BOUNDARY);
    header.setContentLength (_dataOut.length ());
//   header.setValue ("Connection", "Keep-Alive");

    qDebug () << header.toString ();

    _idImageUpload = _httpRequest (url, header, _dataOut);

    qDebug () << "imageUpload:" << fi.absoluteFilePath ();
}