Solved

Delphi HTTP Examples for Client - Server using domain name

Posted on 2010-08-19
8
1,246 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

680 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