Results 1 to 3 of 3

Thread: QHttp has problems with some url's

  1. #1
    Join Date
    Jan 2006
    Location
    Kranj, Slovenia
    Posts
    34
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QHttp has problems with some url's

    Hi!

    I tried example programm from Qt's "Examples and Demos" from section Networking - HTTP Client. I mdified it so it does not look for file name from the URL I give as input. If I try several addresses I download the main file (usually index.php, but I modified the saved file as index.txt for easier reading the content) but I can not get it from this address: "http://www.ednevnik.si/?w=malea" There is somekind of redirection that QHttp can not comprehand. The Error say: "Found". Can some of you take a look of the situation and help me with this matter? When I try to download the file from URL "http://www.rozina.si/6pack/" I receive empty file. It seems to be the problem with all blogs from address www.rozina.si as well as with all blogs from www.ednevnik.si. But a friend that is using PERL was able to get the file from those adresses. Can any of you find an explanation for this? What is happening? I can not explain the failure.
    The attached file should be renamed cpp and is modified file of the Qt's example...

    Regards!
    Luka
    Attached Files Attached Files

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

    Default Re: QHttp has problems with some url's

    Some url need cookie , redirecct 3 or moore url and so....


    in some case use libcurl is moore easy as qthttp...

    http://curl.haxx.se/

    you can grab signal to....

    Qt Code:
    1. #define _USER_AGENT_CURL_APPS "Mozilla/5.0 (Windows; U; Windows NT 5.1; it-CH; rv:1.7.12) Gecko/20050919 Firefox/1.0.7"
    2.  
    3.  
    4. /* Warning get local file contents or remote file contents by curl */
    5. QString Config::file_get_contents(QString fullFileName)
    6. {
    7. QString inside = "";
    8. if (fullFileName.contains("https://", Qt::CaseInsensitive)) {
    9. inside = "No build support to https protocoll";
    10. return inside;
    11. }
    12.  
    13. if ( this->IsNetFile( fullFileName ) )
    14. {
    15. file_put_contents(www_net_file,""); /* remove last action if exist */
    16.  
    17. if ( fullFileName.contains("webdav://", Qt::CaseInsensitive )) {
    18. #ifndef GRABCONFIGPASS
    19. #define GRABCONFIGPASS
    20. #endif
    21. }
    22.  
    23. char *localfile = append( qt2char( cachedir ) , c_www_net_file );
    24. char *cookiefile = append( qt2char( cachedir ) , c_www_cookie_file );
    25. char *url = qt2char( fullFileName );
    26.  
    27. CURL *curl_handle;
    28. FILE *outfile;
    29. curl_global_init(CURL_GLOBAL_ALL);
    30. curl_global_init(CURL_GLOBAL_ALL);
    31. curl_handle = curl_easy_init();
    32. outfile = fopen(localfile, "w");
    33.  
    34. if (outfile!=NULL) {
    35. /* CURLOPT_COOKIE and must have CURLOPT_COOKIEJAR char * (file to write same as php) */
    36. curl_easy_setopt(curl_handle, CURLOPT_URL, url);
    37. curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, TRUE);
    38. curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, cookiefile );
    39. curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION , 1);
    40. curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS , 5);
    41. curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT , timeoutsec );
    42. curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, c_user_agent );
    43. curl_easy_setopt(curl_handle, CURLOPT_FILE, outfile);
    44.  
    45. if (curl_easy_perform(curl_handle)==CURLE_OK) {
    46. fclose(outfile);
    47.  
    48. QFile filecurl(www_net_file);
    49. if (filecurl.size() > 5) {
    50. curlerrormsg = "ok_success";
    51. } else {
    52. curlerrormsg = "Error time out to get remote file"+QString( "%1" ).arg( getExactTime() );
    53. }
    54.  
    55. } else {
    56. curlerrormsg = "Error time out to get remote file"+QString( "%1" ).arg( getExactTime() );
    57. file_put_contents(www_net_file,"");
    58. }
    59. }
    60. /* return grab result from local file */
    61. return file_get_contents(www_net_file);
    62. }
    63.  
    64.  
    65.  
    66.  
    67. /* ok is a fake normal local file init ..... */
    68. QFile file(fullFileName);
    69. if (file.exists()) {
    70. if (file.open(QFile::ReadOnly | QFile::Text)) {
    71. inside =file.readAll();
    72. file.close();
    73. errormsg = "ok_success";
    74. } else {
    75. inside = "no_open_file";
    76. }
    77. } else {
    78. inside = "no_file";
    79. }
    80.  
    81. return inside;
    82. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to patrik08 for this useful post:

    whoops.slo (4th June 2006)

  4. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QHttp has problems with some url's

    I'm not sure about the latter url, but you can get at least contents of "http://www.ednevnik.si/?w=malea" by changing:
    Qt Code:
    1. httpGetId = http->get(url.path(), file);
    To copy to clipboard, switch view to plain text mode 
    to:
    Qt Code:
    1. httpGetId = http->get(url.toString(), file);
    To copy to clipboard, switch view to plain text mode 
    in HttpWindow::downloadFile().
    J-P Nurmi

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

    whoops.slo (4th June 2006)

Similar Threads

  1. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 15:39

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.