Solved

Delphi HTTP Examples for Client - Server using domain name

Posted on 2010-08-19
8
1,227 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
Comment Utility
0
 
LVL 8

Expert Comment

by:GeneralTackett
Comment Utility
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
Comment Utility
hi Aflarin;
Is that Ok for ciuly?
0
 

Author Comment

by:magman5
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 13

Expert Comment

by:aflarin
Comment Utility
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
Comment Utility
Thanks aflarin

HTTPgetfile works well.

Any suggestions for using other HTTP commands ?
0
 
LVL 13

Accepted Solution

by:
aflarin earned 125 total points
Comment Utility
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
Comment Utility
many thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now