PDA

View Full Version : QHttp has problems with some url's



whoops.slo
2nd June 2006, 15:43
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

patrik08
2nd June 2006, 16:02
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....




#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"


/* Warning get local file contents or remote file contents by curl */
QString Config::file_get_contents(QString fullFileName)
{
QString inside = "";
if (fullFileName.contains("https://", Qt::CaseInsensitive)) {
inside = "No build support to https protocoll";
return inside;
}

if ( this->IsNetFile( fullFileName ) )
{
file_put_contents(www_net_file,""); /* remove last action if exist */

if ( fullFileName.contains("webdav://", Qt::CaseInsensitive )) {
#ifndef GRABCONFIGPASS
#define GRABCONFIGPASS
#endif
}

char *localfile = append( qt2char( cachedir ) , c_www_net_file );
char *cookiefile = append( qt2char( cachedir ) , c_www_cookie_file );
char *url = qt2char( fullFileName );

CURL *curl_handle;
FILE *outfile;
curl_global_init(CURL_GLOBAL_ALL);
curl_global_init(CURL_GLOBAL_ALL);
curl_handle = curl_easy_init();
outfile = fopen(localfile, "w");

if (outfile!=NULL) {
/* CURLOPT_COOKIE and must have CURLOPT_COOKIEJAR char * (file to write same as php) */
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, TRUE);
curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, cookiefile );
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION , 1);
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS , 5);
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT , timeoutsec );
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, c_user_agent );
curl_easy_setopt(curl_handle, CURLOPT_FILE, outfile);

if (curl_easy_perform(curl_handle)==CURLE_OK) {
fclose(outfile);

QFile filecurl(www_net_file);
if (filecurl.size() > 5) {
curlerrormsg = "ok_success";
} else {
curlerrormsg = "Error time out to get remote file"+QString( "%1" ).arg( getExactTime() );
}

} else {
curlerrormsg = "Error time out to get remote file"+QString( "%1" ).arg( getExactTime() );
file_put_contents(www_net_file,"");
}
}
/* return grab result from local file */
return file_get_contents(www_net_file);
}




/* ok is a fake normal local file init ..... */
QFile file(fullFileName);
if (file.exists()) {
if (file.open(QFile::ReadOnly | QFile::Text)) {
inside =file.readAll();
file.close();
errormsg = "ok_success";
} else {
inside = "no_open_file";
}
} else {
inside = "no_file";
}

return inside;
}

jpn
3rd June 2006, 00:16
I'm not sure about the latter url, but you can get at least contents of "http://www.ednevnik.si/?w=malea" by changing:

httpGetId = http->get(url.path(), file);
to:

httpGetId = http->get(url.toString(), file);
in HttpWindow::downloadFile().