Results 1 to 20 of 22

Thread: HttpHeader Request only part of an entity

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: HttpHeader Request only part of an entity

    Send a HEAD request to the server, it will reply with the same header (but no body) as if you sent GET. In this header, you will receive Content-length which will be the size of the file as long as you do not include a "Range" header in your HEAD request (else you'll get the size of your range, which isn't what you want).

    Note that not all servers support this, in which case you will be transferring "blind" and will have to depend on a short read.

  2. #2
    Join Date
    Mar 2010
    Posts
    92
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: HttpHeader Request only part of an entity

    Quote Originally Posted by fatjuicymole View Post
    Send a HEAD request to the server, it will reply with the same header (but no body) as if you sent GET. In this header, you will receive Content-length which will be the size of the file as long as you do not include a "Range" header in your HEAD request (else you'll get the size of your range, which isn't what you want).

    Note that not all servers support this, in which case you will be transferring "blind" and will have to depend on a short read.
    yes, I also think it will get by, but really I do not known write in QTcreator how to get respond Http header, I havent example by learn

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

    Default Re: HttpHeader Request only part of an entity

    Come on, man. Simply instead of a "get" request, make a "head" request.

  4. #4
    Join Date
    Mar 2010
    Posts
    92
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: HttpHeader Request only part of an entity

    Quote Originally Posted by wysota View Post
    Come on, man. Simply instead of a "get" request, make a "head" request.
    Qt Code:
    1. QFile qfFileHeader("Header.txt");
    2. if (!qfFileHeader.open(QIODevice::WriteOnly)) {
    3. QMessageBox::information(this, tr("HTTP"),tr("Unable to save the file %1: %2.").arg(qsFileName).arg(qfFileOut->errorString()));
    4. return;
    5. }
    6. QHttpRequestHeader qhrhHeaderRespond("HEAD", qbaUrlPath);
    7. qhrhHeaderRespond.setValue("Host", qsHost);
    8. qhHttpRespond->setHost(qsHost, qhconMode, quUrl.port() == -1 ? 0 : quUrl.port());
    9. if (!quUrl.userName().isEmpty())
    10. qhHttpRespond->setUser(quUrl.userName(), quUrl.password());
    11. qhHttpRespond->request(qhrhHeaderRespond, 0, &qfFileHeader);
    To copy to clipboard, switch view to plain text mode 

    it dont get in File Header.txt
    Last edited by nhs_0702; 23rd April 2010 at 15:11.

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

    Default Re: HttpHeader Request only part of an entity

    I think you misunderstand what a "head" request is.

    http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Mar 2010
    Posts
    92
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: HttpHeader Request only part of an entity

    Quote Originally Posted by wysota View Post
    I think you misunderstand what a "head" request is.

    http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
    must i get content-length in Funcition void HttpWindow::readResponseHeader(const QHttpResponseHeader &responseHeader) by funciton QString s =responseHeader.toString(); ?
    but i get mis information

    Ex:
    + s "HTTP/1.1 200 OK
    Date: Sat, 24 Apr 2010 00:41:00 GMT
    Server: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 PHP/5.2.8
    Last-Modified: Sat, QString

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

    Default Re: HttpHeader Request only part of an entity

    Quote Originally Posted by nhs_0702 View Post
    must i get content-length in Funcition void HttpWindow::readResponseHeader(const QHttpResponseHeader &responseHeader) by funciton QString s =responseHeader.toString(); ?
    but i get mis information
    I have no idea what you mean. Please rephrase the question.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Mar 2010
    Posts
    92
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: HttpHeader Request only part of an entity

    Quote Originally Posted by wysota View Post
    I have no idea what you mean. Please rephrase the question.
    thank you,i was get file size,thank you again

  9. #9
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: HttpHeader Request only part of an entity

    Not every server supports Content-length. You should use it if its there, but you can't depend on it being there. This is why web browsers sometimes say "Downloaded 130KB of unknown" for example.

Similar Threads

  1. set visable part of view
    By ensky_cy in forum Qt Programming
    Replies: 0
    Last Post: 16th December 2009, 10:21
  2. Special character's HTML entity to string
    By Hiba in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2009, 14:05
  3. Qt Tutorial #1 Add-on Part II
    By ShaChris23 in forum Newbie
    Replies: 5
    Last Post: 25th April 2007, 19:00
  4. how to get a part of the string
    By probine in forum Newbie
    Replies: 2
    Last Post: 4th December 2006, 14:37
  5. Qhttp::request(...) method and GET request
    By mikhailt in forum Qt Programming
    Replies: 4
    Last Post: 15th September 2006, 12:26

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.