Results 1 to 14 of 14

Thread: File Binary Upload QHttp find the bug/s

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: File Binary Upload QHttp find the bug/s

    I search on my old php4 script a similar function..... to give arguments on post...

    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($Ffields));
    same as...
    curl_setopt($ch, CURLOPT_POSTFIELDS,"login=foo&password=bar");

    all vars from CURLOPT_POSTFIELDS become $_POST...

    How to find correct header info to send? is possibel that qt cann handle that... or ist faster to bring on curl?



    Qt Code:
    1. $Ffields=array(
    2. "__EVENTTARGET" => "repLang:_ct0:lbLang",
    3. "__EVENTARGUMENT" => 'repLang$_ct0$lbLang',
    4. "__VIEWSTATE" => $this->VIEWSTATE, /* asp secure nummer session read ... and transfer to all page. on read.. */
    5. "dlg1:ctrl1:tbKunde" => "252525",
    6. "dlg1:ctrl1:tbKuerzel" => "2352352",
    7. "dlg1:ctrl1:PasswordTexBox" => "ygygsgsg",
    8. "dlg1:ctrl1:cbPersistentLogin" => "on",
    9. "dlg1:ctrl1:Btn_Login" => "Anmelden");
    10.  
    11. $ch = curl_init();
    12. curl_setopt ($ch, CURLOPT_URL, $url);
    13. curl_setopt ($ch, CURLOPT_POST,true);
    14. curl_setopt ($ch, CURLOPT_USERAGENT, $this->Set_Agent());
    15. curl_setopt($ch, CURLOPT_COOKIEJAR, $this->Workdir.'/also_cookie.txt');
    16. curl_setopt($ch, CURLOPT_COOKIEFILE, $this->Workdir.'/also_cookie.txt');
    17. curl_setopt ($ch, CURLOPT_HEADER, 0);
    18. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($Ffields));
    19. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    20. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    21. curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    22. curl_setopt ($ch, CURLOPT_TIMEOUT, 12);
    23. $resultxml = curl_exec ($ch)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: File Binary Upload QHttp find the bug/s

    Do as I already said -- take a network sniffer, activate it, open your browser, load the form that sends the file, submit the form and check in the sniffer, what headers were sent to the server. Then mimic them using QHttp. And remember that you actually have to POST those key=value pairs. Setting them as headers won't do. You have to properly set the content-length and send the data as content and not as headers. If you use a network sniffer, you'll know exactly how should the data be sent.

  3. #3
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: File Binary Upload QHttp find the bug/s

    I have install http://livehttpheaders.mozdev.org/
    and firefox make so.....

    Only header go to server but not _POST vars arguments.....



    POST /qt/tools.php HTTP/1.1
    Host: ppk.go
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; it-IT; rv:1.7.12) Gecko/20050919 Firefox/1.0.7
    Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    Accept-Language: de-de,it;q=0.8,it-it;q=0.6,en-us;q=0.4,en;q=0.2
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    Referer: http://ppk.go/qt/tools.php
    Content-Type: multipart/form-data; boundary=---------------------------41184676334
    Content-Length: 5604
    -----------------------------41184676334
    Content-Disposition: form-data; name="action"

    beamup
    -----------------------------41184676334
    Content-Disposition: form-data; name="username"

    sfgs
    -----------------------------41184676334
    Content-Disposition: form-data; name="password"

    g<sgsg
    -----------------------------41184676334
    Content-Disposition: form-data; name="qtfile"; filename="gui_upload.ui"
    Content-Type: application/octet-stream



    And I put un code so two method ...


    Qt Code:
    1. void Gui_Upload::BeginnJob()
    2. {
    3. bool method_1 = true;
    4. QString openFilesPath = "/";
    5. QDateTime timer2( QDateTime::currentDateTime() );
    6. const uint MAXWAITING = timer2.addSecs(8).toTime_t();
    7. const QString POSTID = QString( "11478%1\r\n" ).arg( QString::number(MAXWAITING) );
    8. const QString POSTIDEND = QString( "11478%1--\r\n" ).arg( QString::number(MAXWAITING) );
    9. qDebug() << "### POSTID " << POSTID;
    10. QString us = username->text();
    11. QString pa = pass->text();
    12. QString posturl = "http://ppk.go/qt/tools.php?id=test";
    13.  
    14. if (us.size() < 1 or pa.size() < 1) {
    15. QMessageBox::information(this, tr("HTTP"),tr("User Name or Pass not set!"));
    16. return;
    17. }
    18. qDebug() << "### user " << us;
    19. qDebug() << "### pass " << pa;
    20.  
    21. pushButton->setEnabled(false);
    22.  
    23. QString fileName = QFileDialog::getOpenFileName(this,tr("OpenFile"),openFilesPath,tr("All Files (*);;Text Files (*.txt)"));
    24. if (!fileName.isEmpty()) {
    25. qDebug() << "### fileName " << fileName;
    26. }
    27.  
    28.  
    29. /* dear qt set and splitt the url self */
    30. QUrl url(posturl);
    31. qDebug() << "### host " << url.host();
    32. qDebug() << "### path " << url.path();
    33. QHttpRequestHeader header("POST",url.path());
    34. header.setValue("Host",url.host());
    35. header.setValue("User-Agent", "QT4 4.1.3 QHttp troll method 1");
    36. header.setValue("Accept", "text/plain");
    37. header.setValue("Accept-Language", "en-us");
    38. header.setValue("Accept-Encoding", "gzip,deflate");
    39. header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
    40. header.setValue("Keep-Alive", "300");
    41. header.setValue("Connection", "keep-alive");
    42. header.setValue("Referer", "http://ppk.go/qt/tools.php");
    43. header.setValue("Content-Type", "multipart/form-data; boundary=---------------------------"+POSTID);
    44.  
    45. QByteArray bytes;
    46. bytes.append("-----------------------------"+POSTID);
    47. bytes.append("Content-Disposition: form-data; name=\"action\"\r\n");
    48. bytes.append("beamup\r\n");
    49. bytes.append("-----------------------------"+POSTID);
    50. bytes.append("Content-Disposition: form-data; name=\"submit\"\r\n");
    51. bytes.append("Upload\r\n");
    52. bytes.append("-----------------------------"+POSTID);
    53. bytes.append("Content-Disposition: form-data; name=\"username\"\r\n");
    54. bytes.append(us+"\r\n");
    55. bytes.append("-----------------------------"+POSTID);
    56. bytes.append("Content-Disposition: form-data; name=\"password\"\r\n");
    57. bytes.append(pa+"\r\n");
    58. bytes.append("-----------------------------"+POSTID);
    59. bytes.append("Content-Disposition: form-data; name=\"unixtime\"\r\n");
    60. bytes.append(QString::number(MAXWAITING)+"\r\n");
    61.  
    62. if (method_1) {
    63. qDebug() << "### METHOD 1 start ++++++++++++++++++++ ";
    64. QString dateiName;
    65. file = new QFile();
    66. QFileInfo fileInfo(fileName);
    67. file->setFileName(fileName);
    68. dateiName = fileInfo.fileName();
    69.  
    70. bytes.append("-----------------------------"+POSTID);
    71. bytes.append("Content-Disposition: form-data; name=\"qtfile\"; filename=\""+dateiName+"\"\n");
    72. bytes.append("Content-length: " + QString::number(fileInfo.size()));
    73. bytes.append("\nContent-Type: text/plain\n\n");
    74. bytes.append(file->readAll());
    75.  
    76.  
    77. header.setValue("Content-Length", QString::number(fileInfo.size()));
    78.  
    79.  
    80. http_0 = new QHttp(url.host(),80,this);
    81. httpGetId = http_0->request(header, bytes);
    82. qDebug() << "### post httpGetId " << httpGetId;
    83. connect(http_0, SIGNAL(done(bool)), this, SLOT(FinishStream()));
    84. connect(http_0, SIGNAL(dataSendProgress(int,int)), this, SLOT(WriteNowProgress(int,int)));
    85. file->close();
    86. qDebug() << "### METHOD 1 end ++++++++++++++++++++ ";
    87.  
    88. } else {
    89.  
    90. qDebug() << "### METHOD 2 start ++++++++++++++++++++ ";
    91. QUrl www(posturl);
    92. qDebug() << "### host " << www.host();
    93. qDebug() << "### path " << www.path();
    94. QHttp *http = new QHttp(this);
    95. http->setHost(www.host());
    96. QFile *file = new QFile(fileName, http);
    97. file->open(QIODevice::ReadOnly);
    98. connect(http, SIGNAL(done(bool)), this, SLOT(FinishStream()));
    99. http->post(www.path(), file);
    100. qDebug() << "### METHOD 2 end ++++++++++++++++++++ ";
    101. }
    102.  
    103. qDebug() << "### POSTID " << POSTID;
    104. qDebug() << "### POSTID " << POSTID;
    105. qDebug() << "### POSTID " << POSTID;
    106. qDebug() << "### POSTID " << POSTID;
    107. qDebug() << "### POSTID " << POSTID;
    108.  
    109. }
    To copy to clipboard, switch view to plain text mode 

    Result are so .... method 1 or 2 are same .... only header diff
    I work on php5 , debian sarge , and fastcgi apache2 suexec all file is user ppk and apache runn as user ppk.....
    and firefox can upload file and set variabel _POST...

    I suppose qt write class to http on other server ..... or php4



    _SERVER["HTTP_HOST"] ppk.go
    _SERVER["HTTP_USER_AGENT"] QT4 4.1.3 QHttp troll method 1
    _SERVER["HTTP_ACCEPT"] text/plain
    _SERVER["HTTP_ACCEPT_LANGUAGE"] en-us
    _SERVER["HTTP_ACCEPT_ENCODING"] gzip,deflate
    _SERVER["HTTP_ACCEPT_CHARSET"] ISO-8859-1,utf-8;q=0.7,*;q=0.7
    _SERVER["HTTP_KEEP_ALIVE"] 300
    _SERVER["HTTP_CONNECTION"] keep-alive
    _SERVER["HTTP_REFERER"] http://ppk.go/qt/tools.php
    _SERVER["CONTENT_TYPE"] multipart/form-data; boundary=---------------------------114781149811467
    _SERVER["PATH"] /usr/local/bin:/usr/bin:/bin
    _SERVER["SERVER_SIGNATURE"] <address>Apache/2.0.54 (Debian GNU/Linux) DAV/2 PHP/5.0.4-0.9sarge1 mod_perl/1.999.21 Perl/v5.8.4 Server at ppk.go Port 80</address>
    _SERVER["SERVER_SOFTWARE"] Apache/2.0.54 (Debian GNU/Linux) DAV/2 PHP/5.0.4-0.9sarge1 mod_perl/1.999.21 Perl/v5.8.4
    _SERVER["SERVER_NAME"] ppk.go
    _SERVER["SERVER_ADDR"] 192.168.1.32
    _SERVER["SERVER_PORT"] 80
    _SERVER["REMOTE_ADDR"] 192.168.1.34
    _SERVER["DOCUMENT_ROOT"] /home/ppk/www/ppk.go/
    _SERVER["SERVER_ADMIN"] [no address given]
    _SERVER["SCRIPT_FILENAME"] /home/ppk/www/ppk.go/qt/tools.php
    _SERVER["REMOTE_PORT"] 4423
    _SERVER["GATEWAY_INTERFACE"] CGI/1.1
    _SERVER["SERVER_PROTOCOL"] HTTP/1.1
    _SERVER["REQUEST_METHOD"] POST
    _SERVER["QUERY_STRING"] no value
    _SERVER["REQUEST_URI"] /qt/tools.php
    _SERVER["SCRIPT_NAME"] /qt/tools.php
    _SERVER["PHP_SELF"] /qt/tools.php
    _SERVER["argv"]

    Array
    (
    )

    _SERVER["argc"] 0
    _ENV["PATH"] /usr/local/bin:/usr/bin:/bin
    _ENV["PWD"] /
    _ENV["LANG"] C
    _ENV["SHLVL"] 1
    _ENV["_"] /usr/sbin/apache2

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: File Binary Upload QHttp find the bug/s

    Apart from the first one, I didn't understand a single sentence you wrote.

    Does it work now or not?

  5. #5
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: File Binary Upload QHttp find the bug/s

    Not work only header.setValue("Content-Type", "multipart/form-data boundary=---------------------------125282808721657");
    go to server, & no variable and no file ...... go up to server i tink muss work on apache2 and php5 / 6

    I test now http://www.qtforum.de/forum/viewtopic.php?t=2255 is incomming tody on Snippets, Tipps & Tricks

  6. #6
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: File Binary Upload QHttp find the bug/s

    Impossibel to upload file or set variable apache2 & php5.... i discovery a faster method ...
    The key is Webdav http://www.webdav.org/ only window muss install external mount disk tool .... webdrive or netdrive ....

    advantage ... i can check evry time if mounted by hidden file
    if file exist mount otherwise ..... not....

    And send to disk evry file and variable ...

    Qt Code:
    1. void Setting_Gui::WebdavSetup()
    2. {
    3. label_webdav->setText(tr("Your OS Not Support Webdav"));
    4. QStringList diskremote;
    5. QString disksetting = Global_Config(APPLICATION_SETTING,"webdav_root");
    6. #if defined Q_WS_WIN
    7. /* http://ciz.ch/service/98,1142862047/de/ netdrive webdrive */
    8. label_webdav->setText(tr("Window XP/2000 OS: Webdav Root (Radice)"));
    9. QString alfa ="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
    10. diskremote = alfa.split(",");
    11. webdav_root->clear();
    12. int loop= 0 - 1;
    13. int activeselected;
    14. QStringListIterator o(diskremote);
    15. while (o.hasNext()) {
    16. loop++;
    17. QString disker = o.next().toLocal8Bit().constData();
    18. QString diskeree = disker.append(":/");
    19. webdav_root->addItem(diskeree);
    20. if (disksetting == diskeree) {
    21. activeselected = loop;
    22. }
    23. }
    24. webdav_root->setEditable(false);
    25. webdav_root->setCurrentIndex(activeselected);
    26. #endif
    27. #if defined Q_WS_MAC
    28. /* apple + K */
    29. label_webdav->setText(tr("Mac OS: Mount Disk Webdav Root"));
    30. QString listdiron ="/Volumes/";
    31. webdav_root->addItem(disksetting);
    32. /* webdav_root->addItem(listdiron);*/
    33. QDir dir(listdiron);
    34. if (dir.exists()) {
    35. const QFileInfoList list = dir.entryInfoList();
    36. for (int i = 0; i < list.size(); i++)
    37. {
    38. fi = list.at(i);
    39. if (fi.isDir() && fi.fileName() != "." && fi.fileName() != "..") {
    40. QString disker = fi.absoluteFilePath();
    41. QString diskeree = disker.append("/");
    42. webdav_root->addItem(diskeree);
    43. }
    44. }
    45. }
    46. webdav_root->setEditable(false);
    47. #endif
    48.  
    49. #if defined Q_WS_X11
    50. /* http://www.webdav.org/cadaver/ */
    51. label_webdav->setText(tr("Linux OS: Mount Disk Webdav Root"));
    52. QString listdiron ="/mnt/";
    53. webdav_root->setEditable(true);
    54. webdav_root->addItem(disksetting);
    55. webdav_root->addItem(listdiron);
    56. #endif
    57.  
    58. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: File Binary Upload QHttp find the bug/s

    Quote Originally Posted by patrik08
    QString disker = o.next().toLocal8Bit().constData();
    Can't you just write
    Qt Code:
    1. QString disker = o.next();
    To copy to clipboard, switch view to plain text mode 
    ?

    If o.next() contains characters that local encoding can't handle, you will loose information.

  8. The following user says thank you to jacek for this useful post:

    patrik08 (9th June 2006)

Similar Threads

  1. Replies: 13
    Last Post: 1st June 2006, 14:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.