Наваял пробный проект, скомпилил - работать не хочет - HTTPSender.Resultcode возвращает 500.
Помогите разобраться с ситуацией.
- Код: Выделить всё
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
httpsend;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
function DownloadHTTP(URL, TargetFile: string): Boolean;
// Download file; retry if necessary.
// Could use Synapse HttpGetBinary, but that doesn't deal
// with result codes (i.e. it happily downloads a 404 error document)
const
MaxRetries = 3;
var
HTTPGetResult: Boolean;
HTTPSender: THTTPSend;
RetryAttempt: Integer;
begin
Result := False;
RetryAttempt := 1;
HTTPSender := THTTPSend.Create;
try
try
// Try to get the file
HTTPGetResult := HTTPSender.HTTPMethod('GET', URL);
while (HTTPGetResult = False) and (RetryAttempt < MaxRetries) do
begin
Sleep(500 * RetryAttempt);
HTTPGetResult := HTTPSender.HTTPMethod('GET', URL);
RetryAttempt := RetryAttempt + 1;
end;
// If we have an answer from the server, check if the file
// was sent to us.
case HTTPSender.Resultcode of
100..299:
begin
HTTPSender.Document.SaveToFile(TargetFile);
Result := True;
end; //informational, success
300..399: Result := False; // redirection. Not implemented, but could be.
400..499: Result := False; // client error; 404 not found etc
500..599: Result := False; // internal server error
else Result := False; // unknown code
end;
except
// We don't care for the reason for this error; the download failed.
Result := False;
end;
finally
HTTPSender.Free;
end;
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
if DownloadHTTP('http://freepascal.ru/download/projects/GUI-mount.tar.gz','./GUI-mount.tar.gz') then
ShowMessage('OK') else ShowMessage('False');
end;
end.
Добавлено спустя 1 час 10 минут 32 секунды:
Переписал проект на Curl - та же песня. Проблема в том,что приложение не может разрешить доменное имя (не видит dns сервера). Хотя другие приложения работают без проблем (тот же фаерфокс и т.п.).
Добавлено спустя 11 минут 28 секунд:
Создал файл /etc/resolv.conf:
- Код: Выделить всё
nameserver 8.8.8.8
nameserver 8.8.4.4
все заработало как часы и synapse и curl.
Начал копать - оказывается в ubuntu 12.04 убрали (подозреваю что в других версиях так же) /etc/resolv.conf и разрешают имена доменов через группу утилит... ( http://forum.ubuntu.ru/index.php?topic=184435.0 ).
Отсюда вопрос - как, не имея прав root в системе заставить работать приложение с использованием synapse или curl?