Qnetworkaccessmanager Implement Curl Upload form file

Source: Internet
Author: User
Tags curl

The process of sadness I will not say, direct serving.

How to use QT implementation: curl-f [email protected] Http://www.fatjb.com/uploadfile

Qfile file (M_staskplistpath), if (File.exists ()) {    if (!file.open (QIODevice::ReadOnly)) )     {        qmessagebox::warning (This, tr (" Warning "),  tr (" Open task.plist failed! "),  qmessagebox::yes);         return;    }     qbytearray filecontent = file.readall ();     File.close ();         qstring scrlf= "\ r \ n";     qsrand (Qdatetime::currentdatetime (). totime_t ());     qstring b=qvariant (Qrand ()) . ToString () +qvariant (Qrand ()). ToString () +qvariant (Qrand ()). ToString ();    qstring  sboundary= "---------------------------" +b;    qstring sendboundary=scrlf+ "--" + sboundary+ "--" +scrlf;    qstring scontenttype= "multipart/form-data; boundary=" +sboundary;    sboundary= "--" +sboundary+scrlf;    qbytearray  Boundary=sboundary.toascii ();        qbytearray senddata;     senddata.append (boundary);    sboundary = scrlf +  Sboundary;    boundary = sboundary.toascii ();     Senddata.append (QString ("content-disposition: form-data; name=\" file\ ";  filename=\" "+QString (m_ Staskplistpath.toutf8 (). Constdata ()) + "\" "+scrlf). Toascii ());     senddata.append (QString (" Content-transfer-encoding: 8bit "+scrlf). Toascii ());     senddata.append (SCrlf.toAscii ( );     senddata.append (filecontent);     senddata.append ( Sendboundary.toascii ());         qnetworkrequest req (QUrl (m_ Saddress+m_suploadpath));     req. SetHeader (Qnetworkrequest::contenttypeheader, scontenttype.toascii ());     Req.setheader (Qnetworkrequest::contentlengthheader, qvariant (Senddata.size ()). ToString ());     qnetworkreply* preply = m_pmanager->post (Req, senddata);     connect (preply, signal (Error (Qnetworkreply::networkerror)),  slot (networkerror:: Networkerror)));} Else{    qmessagebox::warning (THIS, TR ("Warning"),  tr ("Task.plist does not exist! "),  qmessagebox::yes);}

Why would I know? Next Wireshark grab the bag, then follow the correct package slowly tune to know, sure enough or not lazy.

Qnetworkaccessmanager Implement Curl Upload form file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.