Results 1 to 4 of 4

Thread: Why this code not record var "Source" to file?

  1. #1
    Join Date
    Nov 2012
    Posts
    16
    Qt products
    Qt4

    Default Why this code not record var "Source" to file?

    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();

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Why this code not record var "Source" to file?

    Why do you think it doesn't? What does "source" contain?

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

  3. #3
    Join Date
    Nov 2012
    Posts
    16
    Qt products
    Qt4

    Default Re: Why this code not record var "Source" to file?

    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?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Why this code not record var "Source" to file?

    What do you think the result of a PUT request against a google server should be? That is what you are asking for.

  5. The following user says thank you to ChrisW67 for this useful post:

    alitoh (7th November 2012)

Similar Threads

  1. "Render" Qt dialog window from ".ui" file
    By BitEater in forum Qt Programming
    Replies: 1
    Last Post: 8th July 2011, 14:40
  2. Replies: 1
    Last Post: 10th March 2011, 14:40
  3. Replies: 3
    Last Post: 15th February 2010, 17:27
  4. Replies: 3
    Last Post: 8th July 2008, 19:37
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.