Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delphi HTTP Examples for Client - Server using domain name

Posted on 2010-08-19
8
Medium Priority
?
1,277 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
[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
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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

722 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