Recent

Author Topic: ICS - Internet Component Suite for Lazarus?  (Read 15332 times)

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: ICS - Internet Component Suite for Lazarus?
« Reply #15 on: August 20, 2014, 04:20:04 pm »
New problem:
Mmmm, yeah.... I can't copy and paste that message to Google translate so i'll have to guess.
But Error 403 seems your download file is not available on the internet.

Did you change the URL in the example to your own file?
You could try a testfile of 25MB (http://www.colocenter.nl/speedtest/25mb.bin)
In unit2.pas:
Code: [Select]
...
procedure DonwloaFile(OnProgress: TOnProgress);
const
  cUrl = 'http://www.colocenter.nl/speedtest/100mb.bin';
  cFile = 'testfile25mb.bin';
var
...

GoodBoyAlex

  • New member
  • *
  • Posts: 9
Re: ICS - Internet Component Suite for Lazarus?
« Reply #16 on: August 20, 2014, 06:12:55 pm »
strange, but there is no error. But if you enter in the browser that the file I'm trying to download, it's all right!
for example, http://www.rnrmm.ru/mods/mm2/victorsmods/bgplus/BGPlus_3.mm2
« Last Edit: August 20, 2014, 06:23:15 pm by GoodBoyAlex »

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: ICS - Internet Component Suite for Lazarus?
« Reply #17 on: August 20, 2014, 06:16:38 pm »
strange, but there is no error. But if you enter in the browser that the file I'm trying to download, it's all right!
What file?
What do you mean... "there is no error"?

Does the url http://www.colocenter.nl/speedtest/25mb.bin work ok?

It could be that the server checks if the user-agent is set correctly.

If you give us the URL we could check here.

GoodBoyAlex

  • New member
  • *
  • Posts: 9
Re: ICS - Internet Component Suite for Lazarus?
« Reply #18 on: August 20, 2014, 06:25:21 pm »
strange, but there is no error. But if you enter in the browser that the file I'm trying to download, it's all right!
What file?
What do you mean... "there is no error"?

Does the url http://www.colocenter.nl/speedtest/25mb.bin work ok?

It could be that the server checks if the user-agent is set correctly.

If you give us the URL we could check here.
Yes, yours url works fine. But this url -- sadly, not http://www.rnrmm.ru/mods/mm2/victorsmods/bgplus/BGPlus_3.mm2

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: ICS - Internet Component Suite for Lazarus?
« Reply #19 on: August 20, 2014, 06:37:34 pm »
Yes, yours url works fine. But this url -- sadly, not http://www.rnrmm.ru/mods/mm2/victorsmods/bgplus/BGPlus_3.mm2
Yep... just as i expected.
That site doesn't like other downloaders than browsers.
It checks the user-agent of the requester.

You can simply add the following line (with vHTTP.RequestHeaders.Add) to the DonwloaFile-procedure.
(It will make your application look like Chrome on Windows 7 to that site)
Code: [Select]
procedure DonwloaFile(OnProgress: TOnProgress);
const
  cUrl = 'http://www.rnrmm.ru/mods/mm2/victorsmods/bgplus/BGPlus_3.mm2';
// ....
begin
  try
    vHTTP := TFPHTTPClient.Create(nil);

    // add this line
    vHTTP.RequestHeaders.Add('User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36');

    vHTTP.HTTPMethod('HEAD', cUrl, nil, [200]);
// ....

B.T.W. you might want to change that name of the DonwloaFile-procedure.
(I suspect that was a typo in the original example)

Edit:
Any user-agent will do for that site.
So this will work too:
Code: [Select]
    vHTTP.RequestHeaders.Add('User-Agent:MyApplication');

But maybe emulating a real browser (like Chrome) is better if you download from other sites which would check this user-agent too.
« Last Edit: August 20, 2014, 06:41:57 pm by rvk »

GoodBoyAlex

  • New member
  • *
  • Posts: 9
Re: ICS - Internet Component Suite for Lazarus?
« Reply #20 on: August 20, 2014, 06:50:03 pm »
Yes, yours url works fine. But this url -- sadly, not http://www.rnrmm.ru/mods/mm2/victorsmods/bgplus/BGPlus_3.mm2
Yep... just as i expected.
That site doesn't like other downloaders than browsers.
It checks the user-agent of the requester.

You can simply add the following line (with vHTTP.RequestHeaders.Add) to the DonwloaFile-procedure.
(It will make your application look like Chrome on Windows 7 to that site)
Code: [Select]
procedure DonwloaFile(OnProgress: TOnProgress);
const
  cUrl = 'http://www.rnrmm.ru/mods/mm2/victorsmods/bgplus/BGPlus_3.mm2';
// ....
begin
  try
    vHTTP := TFPHTTPClient.Create(nil);

    // add this line
    vHTTP.RequestHeaders.Add('User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36');

    vHTTP.HTTPMethod('HEAD', cUrl, nil, [200]);
// ....

B.T.W. you might want to change that name of the DonwloaFile-procedure.
(I suspect that was a typo in the original example)

Edit:
Any user-agent will do for that site.
So this will work too:
Code: [Select]
    vHTTP.RequestHeaders.Add('User-Agent:MyApplication');

But maybe emulating a real browser (like Chrome) is better if you download from other sites which would check this user-agent too.
BIG thank you! Its really work.