tags:

views:

591

answers:

2

I'm using TNMHTTP in Delphi to retrieve the code from a webpage. The code is relatively simple:

NMHTTP1 := TNMHTTP.Create(Self);
NMHTTP1.InputFileMode := FALSE;
NMHTTP1.OutputFileMode := FALSE;
NMHTTP1.ReportLevel := Status_Basic;
NMHTTP1.TimeOut := 3000;

URL := 'http://www....';
NMHTTP1.Get(URL); 
S := NMHTTP1.Body;

I am catching exceptions in a try/except block, but that is not the problem.

The problem is that on executing the NMHTTP1.Get method when the URL is a redirect, that method does not return and the program hangs. This is despite the fact that I've put a timeout of 3000 seconds in.

So I see three possible ways of solving this (in order of easiest to hardest for me to modify my program):

  1. Do whatever is necessary to get the NMHTTP1.Get method to respond.

  2. Do some sort of check in advance of the NMHTTP1.Get statement to see if the URL is a redirect and get the URL it is redirecting to.

  3. Use another method to get a webpage using Delphi. When I wrote this, I used Delphi 4 and did not have Indy. I now have Delphi 2009, so I would be willing to use something that works in it (maybe INDY) if a simple #1 or #2 answer is not available.

I would love to get an answer from someone that will work for me. Thanks in advance.

+3  A: 

I can advice you to switch to Indy. They are great for a lot of network protocols (with the exception of the IRC protocol). There are nice examples included so you can examine the working examples yourself.

Also have a look at http://www.indyproject.org/index.en.aspx for more information on indy.

Gamecat
+3  A: 

I would avoid the NetMasters controls, period.

Instead, you can use Indy's IdHTTP component, which has a RedirectMaximum property (defaults to 15) and an OnRedirect event in case you want to track the details.

Bruce McGee