Problem with GET method and GZIP decoding
Posted: 2020-11-21 02:49:39
Hi, I have noticed a two problems with downloading the web pages, and also tried to find a solution.
1. Problem downloading the pages from youtube when use the GET method, example:
data := GetPage('https://www.youtube.com/results?search_query=trailer');
I looked at the source code of AMC and also do some tests with example codes of Indy package.
It looks like the problem is with '*/*' ContentType of request header in GET method, line:
GetScriptWin.http.Request.ContentType := '*/*';
("function GetPage(const address, referer, cookies: string): string;" located in getscript.pas file)
Perhaps you just need to remove that ContentType line to fix it. See below link as a reference:
https://stackoverflow.com/questions/566 ... t-requests
2. The other problem, not related to above is support for gzip Encoding. Downloaded web page encoded with gzip compression is not automatically decoded.
You can easily recognize it, downloaded data starts with 1F 8B 08 bytes.
To test it, you can force gzip encoding by adding below line to above mentioned GetPage() function.
GetScriptWin.http.Request.AcceptEncoding := 'gzip';
Then just try to download google web page and check data content:
data := GetPage('https://www.google.com');
Possible that update of Indy component to latest version will be enough to fix that issue.
Unfortunately, I don't have the Delphi software to compile AMC source code files, and used free Lazarus/FPC compiler for partial testing only.
1. Problem downloading the pages from youtube when use the GET method, example:
data := GetPage('https://www.youtube.com/results?search_query=trailer');
I looked at the source code of AMC and also do some tests with example codes of Indy package.
It looks like the problem is with '*/*' ContentType of request header in GET method, line:
GetScriptWin.http.Request.ContentType := '*/*';
("function GetPage(const address, referer, cookies: string): string;" located in getscript.pas file)
Perhaps you just need to remove that ContentType line to fix it. See below link as a reference:
https://stackoverflow.com/questions/566 ... t-requests
2. The other problem, not related to above is support for gzip Encoding. Downloaded web page encoded with gzip compression is not automatically decoded.
You can easily recognize it, downloaded data starts with 1F 8B 08 bytes.
To test it, you can force gzip encoding by adding below line to above mentioned GetPage() function.
GetScriptWin.http.Request.AcceptEncoding := 'gzip';
Then just try to download google web page and check data content:
data := GetPage('https://www.google.com');
Possible that update of Indy component to latest version will be enough to fix that issue.
Unfortunately, I don't have the Delphi software to compile AMC source code files, and used free Lazarus/FPC compiler for partial testing only.