PDA

View Full Version : QHttp "PUT METHOD" QT Problem File Upload. RFC 2616



patrik08
25th October 2006, 00:54
Why QHttp can not upload file on fast PUT Method?

bytes 0 send incomming I have other script written on libcurl and runnig only on Window...
I like make this Put Method avaiable to all 3 os...

How i find the Bug?... on server is not required user or pass.... (only a valid cookie and libbcurl recive it ok...)

server say only:

<h1>Request Entity Too Large</h1>
The requested resource<br />/info.php<br />
does not allow request data with PUT requests, or the amount of data provided in
the request exceeds the capacity limit.

- bytes 0 send incomming </pa





/* class QCurl public */
void StartPutFile()
{
wwwput = new QHttp();
wwwput->setUser("","");
connect(wwwput, SIGNAL(requestFinished(int, bool)), this, SLOT(httpRequestFinished(int, bool)));
connect(wwwput, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
}
/* RFC 2616 */
/* class QCurl public Http PUT Method */
int Sender( QString beamupfile , QString posturl , QString LogFileapps )
{
QFileInfo beamfaq(beamupfile);
QString dateiName = beamfaq.fileName();
QUrl url(posturl);
wwwput->setHost(url.host(), 80);
logFile = new QFile(LogFileapps);
logFile->open(QIODevice::ReadWrite);
putFile = new QFile(beamupfile);
putFile->open(QIODevice::ReadOnly);
qint64 sizeallow = putFile->size();
QHttpRequestHeader header("PUT", url.path(),1,1); /* header */
header.setValue("Host", url.host());
header.setValue("Connection", "keep-alive");
header.setValue("User-Agent", WEBAGENTNAME );
header.setValue("Content-length",QString::number(sizeallow));
qDebug() << "### beamfaq.size() " << sizeallow;
putid = wwwput->request(header, putFile, logFile);
return putid;
}








/* the server script work on libcurl PUT METHOD only window! and large file go up / Mac=no / Linux=no*/
<?php
if ($_SERVER['REQUEST_METHOD'] == "PUT") {
$content = file_get_contents("php://input");
$kb=file_put_contents(date("U")."_aa.pdf",$content);
header('Content-Type: text/xml; charset=utf-8');
echo "\n";
print '<parsererror xmlns="http://www.mozilla.org/newlayout/xml/parsererror.xml">';
print $_SERVER['HTTP_USER_AGENT']." - bytes ".$kb." send incomming ";
print '</parsererror>';
exit;
}

/*
curl_easy_setopt(curl_handle, CURLOPT_URL, sendurlwww );
curl_easy_setopt(curl_handle, CURLOPT_UPLOAD , TRUE );
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, TRUE);
curl_easy_setopt(curl_handle, CURLOPT_PUT , TRUE);
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT , 60 );
curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, xwcookiefile );
curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, xwcookiefile );
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "QT4 / PPK_W @ciz.ch" );
curl_easy_setopt(curl_handle,CURLOPT_STDERR , logfile );
curl_easy_setopt(curl_handle,CURLOPT_INFILE , beamupfile );
curl_easy_setopt(curl_handle,CURLOPT_INFILESIZE , des.size());
*/
?>

wysota
25th October 2006, 07:49
I don't see a bug in Qt. Put works fine for me. Where do you see the bug anyway? It is the server which emits the error, not the client. I'd look for the bug in your code and not QHttp code (maybe "sizeallow" is incorrect? You're not checking for errors anywhere in your code).

patrik08
25th October 2006, 12:46
I don't see a bug in Qt. Put works fine for me. Where do you see the bug anyway? It is the server which emits the error, not the client. I'd look for the bug in your code and not QHttp code (maybe "sizeallow" is incorrect? You're not checking for errors anywhere in your code).

Yes by me running only on window now ... sizeallow comming from QFileInfo size()...
Problem is this code not work on Mac Tiger Untested on Linux....

I suppose Header is bad! PUT require a HTTP 1.1 Header .... is this here incomlete? to PUT method...


QHttpRequestHeader header("PUT", url.path(),1,1); /* header */
header.setValue("Host", url.host());
header.setValue("Connection", "keep-alive");
header.setValue("User-Agent", "Clientt XX");
header.setValue("Content-length",QString::number(sizeallow)); /* QFileInfo size(). */

wysota
25th October 2006, 17:09
Does
putFile->open(QIODevice::ReadOnly); return true?
Does
qint64 sizeallow = putFile->size(); return valid size?
Does
header.toString() return a correct http header?

patrik08
25th October 2006, 19:29
Is Work :-) : super ......

i comment out

///////header.setValue("Content-length",QString::number(sizeallow));

file size value .... and is incomming....

& log file say ...

....> bytes 4614 send incomming </.....

now i test on mac & linux... tanks...

The PUT Upload is faster as POST .... and easy ... now if QT4 can accept cookie i remove my libcurl ...

Why cookie? client send a small post form + file info mime ecc... to -> server:
server send a cookie ticket to -> client & client is allow to insert PUT file nrxxxx to next 30 min. how QT can learn Cookie management?




void StartPutFile()
{
wwwput = new QHttp();
wwwput->setUser("","");
connect(wwwput, SIGNAL(requestFinished(int, bool)), this, SLOT(httpRequestFinished(int, bool)));
connect(wwwput, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)), this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
}
/* RFC 2616 */
/* class QCurl public Http PUT Method */
int Sender( QString beamupfile , QString posturl , QString LogFileapps )
{
QFileInfo beamfaq(beamupfile);
QString dateiName = beamfaq.fileName();
QUrl url(posturl);
wwwput->setHost(url.host(), 80);
logFile = new QFile(LogFileapps);
logFile->open(QIODevice::ReadWrite);
putFile = new QFile(beamupfile);
putFile->open(QIODevice::ReadOnly);
qint64 sizeallow = putFile->size();
QHttpRequestHeader header("PUT", url.path(),1,1); /* header */
header.setValue("Host", url.host());
header.setValue("Connection", "keep-alive");
/////header.setValue("User-Agent", WEBAGENTNAME );
///////header.setValue("Content-length",QString::number(sizeallow));
qDebug() << "### header.toString() " << header.toString();
qDebug() << "### beamfaq.size() " << sizeallow;
putid = wwwput->request(header, putFile, logFile);
return putid;
}

wysota
25th October 2006, 19:36
how QT can learn Cookie management?

Just set the "Cookie" header with the proper content of the cookie in the QHttp object.

patrik08
25th October 2006, 20:15
Just set the "Cookie" header with the proper content of the cookie in the QHttp object.

Server can send Cookie but client QT4 cant not read....! I dont say how? (only libcurl can..)
If I send a header fill ... "Filename" user & ..... Client not say a relative path from server to save the PUT file upload?
I make a simpled handshake client & server and transmit to client a cookie contenent the relative path to save...




<?php
define ("SOTIME",date("l dS of F Y h:i:s A"));
/* incomming file */
if ($_SERVER['REQUEST_METHOD'] == "PUT") {
$kb = 0;
$nrfile = $_COOKIE["UNIXCIZNUMMER"]; /* cms file NR. (Unixtime NULL nr. )*/
$dirappend = $_COOKIE["TIPERMISO"]; /* path & file name cookie from client */
if ( strlen($nrfile) > 9 ) {
$apie = new CMS_Page($nrfile.'-it',false); /* false not write operation */
$Pathw = $apie->Assign_File(); /* file nummer index must exist! */
if (is_file($Pathw)) {
$destcoso = $apie->Assign_Path().DIRECTORY_SEPARATOR.$dirappend;
$content = file_get_contents("php://input"); /* grab file */
$kb=file_put_contents($destcoso,$content);
}
}
if ($kb > 3) {
setcookie ("ARIVOSSTRUEDATACIZ",SOTIME, time() - 3600); /* confirm success ! */
}
header('Content-Type: text/xml; charset=utf-8');
echo "\n";
print '<parsererror xmlns="http://www.mozilla.org/newlayout/xml/parsererror.xml">';
print $destcoso." - ".$_COOKIE["UNIXCIZNUMMER"] . "\n\n\n";
print $_SERVER['HTTP_USER_AGENT']." - bytes ".$kb." send ".$_COOKIE["ARIVOSSTRUE"];
print '</parsererror>';
exit;
}
?>



After client as incomming the cookie confir success .. i delete the device ...

wysota
25th October 2006, 22:02
Server can send Cookie but client QT4 cant not read....!
Why not?

It can read any header therefore I don't see a problem reading "set-cookie" header, you just need to access the response object through QHttp interface.


If I send a header fill ... "Filename" user & ..... Client not say a relative path from server to save the PUT file upload?
I don't have a slightest idea what you mean :)



<?php
define ("SOTIME",date("l dS of F Y h:i:s A"));
...
?>

Are these snippets of yours really necessary? They are completely irrelevant and you keep pasting them in each post you write. We are very happy you can produce PHP code and you wish to transfer some part of the functionality to a Qt based system, but I don't see a reason for flooding the forum with irrelevant php code. Don't be mad, I'm just doing my moderator job :)