멀티 쓰레드를 사용하는 즉시 파일을 다운로드하고 추출하는 양식이 있습니다. 내가 github에있는 파일에 문제가 있기 때문에 나는 금지 된 오류를 제공하는 디버그에서 내 애플 리케이션을 실행하고 있기 때문에.indy가 금지 된 github에서 파일을 다운로드 하시겠습니까?
내 양식 GitHub의에서 아무것도를 다운로드 할 수 없습니다하지만 난 다른 곳에서 다운로드 할 수 있습니다. 왜 이런 "금지 된"오류가 발생하고 어떻게 해결할 수 있습니까?
양식 코드 :
unit uOxideModInstaller;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.ComCtrls,
Vcl.StdCtrls, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP, System.Zip, ActiveX,
IdSSLOpenSSL;
type
TDownload = class;
Tfrmoxidemodinstaller = class(TForm)
pb1: TProgressBar;
btn1: TButton;
procedure FormShow(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TDownload = class(TThread)
private
httpclient: TIdHTTP;
url: string;
filename: string;
maxprogressbar: integer;
progressbarstatus: integer;
procedure ExtractZip(ZipFile: string; ExtractPath: string);
procedure idhttp1Work(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Int64);
procedure idhttp1WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
AWorkCountMax: Int64);
procedure UpdateProgressBar;
procedure SetMaxProgressBar;
protected
procedure Execute; override;
public
constructor Create(CreateSuspended: boolean; aurl, afilename: string);
destructor Destroy; override;
end;
var
frmoxidemodinstaller: Tfrmoxidemodinstaller;
implementation
{$R *.dfm}
{ Thread }
constructor TDownload.Create(CreateSuspended: boolean; aurl, afilename: string);
begin
inherited Create(CreateSuspended);
httpclient := TIdHTTP.Create(nil);
httpclient.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(httpclient);
httpclient.HandleRedirects := True;
httpclient.OnWorkBegin := idhttp1WorkBegin;
httpclient.OnWork := idhttp1Work;
url := aurl;
filename := afilename;
end;
procedure TDownload.idhttp1Work(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Int64);
begin
progressbarstatus := AWorkCount;
Queue(UpdateProgressBar);
end;
procedure TDownload.idhttp1WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
AWorkCountMax: Int64);
begin
maxprogressbar := AWorkCountMax;
Queue(SetMaxProgressBar);
end;
procedure TDownload.Execute;
var
Stream: TMemoryStream;
begin
Stream := TMemoryStream.Create;
try
httpclient.Get(url, Stream);
Stream.SaveToFile(filename);
frmoxidemodinstaller.Caption := 'Done Downloading. Extracting...';
ExtractZip('oxide.zip', GetCurrentDir);
finally
Stream.Free;
end;
end;
procedure TDownload.UpdateProgressBar;
var
ZipFile: string;
begin
frmoxidemodinstaller.pb1.Position := progressbarstatus;
frmoxidemodinstaller.Caption := 'Downloading...';
end;
procedure TDownload.SetMaxProgressBar;
begin
frmoxidemodinstaller.pb1.Max := maxprogressbar;
end;
destructor TDownload.Destroy;
begin
FreeAndNil(httpclient);
inherited Destroy;
end;
procedure TDownload.ExtractZip(ZipFile, ExtractPath: string);
begin
if TZipFile.IsValid(ZipFile) then
begin
TZipFile.ExtractZipFile(ZipFile, ExtractPath);
DeleteFile(ZipFile);
frmoxidemodinstaller.Caption := 'Done.';
frmoxidemodinstaller.btn1.Enabled := True;
end
else
begin
frmoxidemodinstaller.Caption := 'Error Extracting files';
end;
end;
procedure Tfrmoxidemodinstaller.btn1Click(Sender: TObject);
begin
Close;
end;
procedure Tfrmoxidemodinstaller.FormShow(Sender: TObject);
var
DownloadThread: TDownload;
link: string;
begin
pb1.Position := 0;
btn1.Enabled := False;
frmoxidemodinstaller.Caption := 'Starting Download...';
link := 'https://www.github.com/OxideMod/Oxide/releases/download/latest/Oxide-Rust.zip';
DownloadThread := TDownload.Create(true, link, 'oxide.zip');
DownloadThread.FreeOnTerminate := true;
DownloadThread.Start;
end;
end.
사용자 에이전트? 말하기 힘듭니다. 그들은 API를 가지고 있기 때문에 웹 브라우저로 확인되지 않은 다른 클라이언트를 차단하려고합니다. 네가 척하는 척 해봐. – Victoria
api를 통해 어떻게 다운로드 할 수 있는지 알고 계십니까? 이전에 외부 API를 사용한 적은 한번도 없었습니다 – Adriaan
[최신 출시 방법] (https://developer.github.com/v3/repos/releases/#get-the-latest-release)입니다. 하지만 먼저 자신을 승인해야합니다 (토큰을 응용 프로그램 사용자와 공유해야합니다). – Victoria