Solved

Indy HTTP

Posted on 2002-05-23
3
268 Views
Last Modified: 2010-04-04
Hi, Im using the Indy HTTP client in D6. Is there an easy way to check if an URL points to a binary file? I would like to skip links pointing to binary files.

Thanks
0
Comment
Question by:pede
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
aubs earned 50 total points
ID: 7029850
You could use the Head method and analyse the contentType to see what sort of file it is:


HTTP := TIdHTTP.Create(nil);
  with HTTP do
try
      Head(URL_in_question);
      FileType := Response.ContentType;
      if Pos('text', LowerCase(FileType)) = 0 then //a file - not a text/html page
...

Aubs

0
 
LVL 2

Expert Comment

by:aubs
ID: 7029866
An alternative is to look at the URL extension:


Type TFileType=(ftUnknown, ftImage, ftPage, ftZip, ftMovie, ftReal, ftPDF, ftExe);

...

function ReverseString(StrIn: String): String;
var
  i: integer;
  revStr: String;
begin
     revStr:= '';
  for i:= length(StrIn) downto 1 do
    revStr:= revStr + StrIn[i];
  Result:= revStr;
end;

function FileType(URL: String): TFileType;
begin
  URL:= ReverseString(URL);
  URL:= Copy(URL, 1, Pos('.',URL) - 1);
  URL:= lowerCase(ReverseString(URL));
  if Pos(URL, 'html txt')>0 then
       Result:= ftPage
  else if Pos(URL, 'gif jpg bmp jpeg')>0 then
       Result:= ftImage
  else if Pos(URL, 'zip')>0 then
       Result:= ftZip
  else if Pos(URL, 'mpg mpeg avi mov')>0 then
       Result:= ftMovie
  else if Pos(URL, 'rm')>0 then
       Result:= ftReal
  else if Pos(URL, 'pdf')>0 then
       Result:= ftPDF
  else if Pos(URL, 'exe')>0 then
       Result:= ftExe

  else
    Result:= ftUnknown;
end;

...

    if  FileType = ftPage then //html page
       getPage()....
    else if  FileType = ftMovie then
       getMovieFile()...

etc.


Aubs


0
 
LVL 1

Author Comment

by:pede
ID: 7031571
Great! Exactly what I needed.
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question