PDA

View Full Version : Why this code not record var "Source" to file?



lapdx
6th November 2012, 18:24
QNetworkRequest request;
networkManager = new QNetworkAccessManager(this);
request.setUrl(QUrl("http://qt.nokia.com"));
request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
networkReply = networkManager->get(request);
networkReply=networkManager->put(request,source);


QFile file("out1.txt");
file.open(QIODevice::WriteOnly | QIODevice::Text);
file.seek(0);
file.write(source);
file.close();

ChrisW67
6th November 2012, 21:10
Why do you think it doesn't? What does "source" contain?

BTW: Nothing Do you know what an HTTP PUT request is?

lapdx
7th November 2012, 06:29
My code:
void MainWindow::getHttp(){
QNetworkRequest request;
networkManager = new QNetworkAccessManager(this);
request.setUrl(QUrl("http://www.google.ru"));
request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
networkReply = networkManager->get(request);
networkReply=networkManager->put(request,source);
connect(networkReply, SIGNAL(finished()), this, SLOT(wFile()));
}
void MainWindow::wFile(){

QFile file("out.txt");
file.open(QIODevice::WriteOnly | QIODevice::Text);
file.seek(0);
file.write(networkReply->readAll());
file.close();
}

Result in file:

<!DOCTYPE html>
<html lang=en>
<meta charset=utf-8>
<meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
<title>Error 405 (Method Not Allowed)!!1</title>
<style>
*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px }body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
</style>
<a href=//www.google.com/><img src=//www.google.com/images/errors/logo_sm.gif alt=Google></a>
<p><b>405.</b> <ins>That’s an error.</ins>
<p>The request method <code>PUT</code> is inappropriate for the URL <code>/</code>. <ins>That’s all we know.</ins>

It's false answer of google.com.

I want get full start page of google. How to do it? How send headers.....yeah?

ChrisW67
7th November 2012, 08:04
What do you think the result of a PUT request against a google server should be? That is what you are asking for.