SHARE
TWEET

Curl + Qt

a guest Jul 31st, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void ServerRest::sendPOST(const QString value)
  2. {
  3.  
  4.     QUrl url("http://localhost:8888");
  5.     QNetworkRequest request;
  6.     request.setUrl(url);
  7.  
  8.     QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
  9.  
  10.     QFile *file = new QFile("/media/1TB/Картинки/RWy6ONzK6oo.jpg");
  11.     file->open(QIODevice::ReadOnly);
  12.  
  13.     QHttpPart image;
  14.     image.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(file->size()));
  15.     image.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("name=\"image\"; filename=\"RWy6ONzK6oo.jpg\""));
  16.  
  17.     image.setBodyDevice(file);
  18.     file->setParent(multipart);
  19.  
  20.     multipart->append(image);
  21.  
  22.     QNetworkAccessManager *manager = new QNetworkAccessManager(this);
  23.     QNetworkReply *reply = manager->post(request, multipart);
  24.     multipart->setParent(reply);
  25.  
  26.     connect(reply, &QNetworkReply::finished, this, &ServerRest::replyTEST);
  27.  
  28.  
  29.  
  30. //    CURL                *curl = nullptr;
  31. //    CURLcode            errorCodeCurl;
  32. //    struct curl_httppost *post  = nullptr;
  33. //    struct curl_httppost *ptr   = nullptr;
  34.  
  35. //    QByteArray url  = value.toUtf8();
  36. //    QMap<QString, QByteArray> buffer;
  37.  
  38. //    for(auto path : fileQmlPath)
  39. //    {
  40. //        QStringList list = path.split(QDir::separator());
  41. //        QString nameFile = list.last().remove(",");
  42.  
  43.  
  44. //        QFile file(path.remove(","));
  45.  
  46. //        if(!file.open(QIODevice::ReadOnly)){
  47. //                qDebug() << "Error open";
  48. //                return;
  49. //        }
  50.  
  51. //        QByteArray send = file.readAll();
  52. //        buffer[nameFile] = send;
  53.  
  54. //    }
  55.  
  56. //    QMapIterator<QString, QByteArray> iter(buffer);
  57. //    while(iter.hasNext())
  58. //    {
  59. //        iter.next();
  60. //        curl_formadd(&post, &ptr,
  61. //                     CURLFORM_COPYNAME,"image",
  62. //                     CURLFORM_BUFFER, iter.key().toStdString().data(),
  63. //                     CURLFORM_BUFFERPTR, iter.value().data(),
  64. //                     CURLFORM_BUFFERLENGTH, iter.value().size(),
  65. //                     CURLFORM_END);
  66.  
  67. //    }
  68.  
  69. //    curl = curl_easy_init();
  70.  
  71. //    if(curl)
  72. //    {
  73. //        curl_easy_setopt(curl, CURLOPT_URL, url.data());
  74. //        curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
  75.  
  76. //        errorCodeCurl = curl_easy_perform(curl);
  77.  
  78. //        if(errorCodeCurl != CURLE_OK)
  79. //        {
  80. //            qDebug() << "Curl Error Connect";
  81. //            qDebug() << "---> " << curl_easy_strerror(errorCodeCurl);
  82. //        }
  83. //    }
  84.  
  85.  
  86. //    curl_easy_cleanup(curl);
  87. //    curl_formfree(post);
  88. //    fileQmlPath.clear();
  89.  
  90.  
  91. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top