Solved

Delphi HTTP Examples for Client - Server using domain name

Posted on 2010-08-19
8
1,238 Views
Last Modified: 2013-11-23
I would like to retrieve files from a server using HTTP. No password rigt now, but will have do use on soon.  I would also like to be able to view directories on the server and delete files (with permission). I would also like to be able to send the server HTTP commands and parse results as a learning exercise.

I have the Indy Components and they look very powerful. I have tried their Client example to connect to a host without success. Probably because I am using a domain name instead of the IP adress (which I do not have). Not sure if this is the best approach to my problem.

0
Comment
Question by:magman5
8 Comments
 
LVL 13

Expert Comment

by:aflarin
ID: 33482469
0
 
LVL 8

Expert Comment

by:GeneralTackett
ID: 33489567
Is writing an ISAPI dll within the realm of what you can do?  If so I have examples that do just what you want.
0
 
LVL 14

Expert Comment

by:systan
ID: 33536165
hi Aflarin;
Is that Ok for ciuly?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:magman5
ID: 33554730
thanks aflarin
most useful (in future), however I do not have control of the server. I just want to send it HTTP commands.

GeneralTackett
thanks for the suggestion. I have no idea what ISAPI is - can you point me in the direction of some good explanations so I can consider your suggestion.
0
 
LVL 13

Expert Comment

by:aflarin
ID: 33556219
hi Systan. why not?

@magman5
>> I just want to send it HTTP commands.

Here is sending Get command to get html and files:

uses
  IdHttp;

function HTTPGet( const URL: string ): string;
var
  IdHTTP1: TIdHTTP;
begin
  IdHTTP1:= TIdHTTP.Create(nil);
  try
    IdHTTP1.HandleRedirects := True;
    Result:= IdHTTP1.Get( URL );
  finally
    IdHTTP1.Free;
  end;
end;

procedure HTTPGetFile( const URL, FileName: string );
var
  IdHTTP1: TIdHTTP;
  fs: TFileStream;
begin
  IdHTTP1:= TIdHTTP.Create(nil);
  try
    IdHTTP1.HandleRedirects := True;

    fs:= TFileStream.Create(FileName, fmCreate );
    try
      IdHTTP1.Get( URL, fs );
    finally
      fs.Free;
    end;

  finally
    IdHTTP1.Free;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Text:= HTTPGet( 'http://google.com' );
  HTTPGetFile( 'http://download.thinkbroadband.com/5MB.zip', 'c:\test.zip' );
end;
0
 

Author Comment

by:magman5
ID: 33564803
Thanks aflarin

HTTPgetfile works well.

Any suggestions for using other HTTP commands ?
0
 
LVL 13

Accepted Solution

by:
aflarin earned 125 total points
ID: 33564851
TidHTTP component has Post, Get, Trace and Head methods to appropriate HTML commands.

Also it has universal DoRequest method for all HTML commands

procedure DoRequest(const AMethod: TIdHTTPMethod; AURL: string; const ASource: TStream; const AResponseContent: TStream); virtual;

where TIdHTTPMethod is

TIdHTTPMethod = (hmHead, hmGet, hmPost, hmOptions, hmTrace, hmPut, hmDelete, hmConnect);
0
 

Author Closing Comment

by:magman5
ID: 33564916
many thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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