Çağırdığım web servisin iletilen bilgilerle hazırladığı 2 tane JPG dosyasını download etmem gerekiyor. Dosyalardan 33 K boyutunda olan her seferinde sorunsuz olarak indirilirken, 200-230 K civarında olan dosyada genellikle IdReadTimeout exception ortaya çıkıyor. Bazen de dosya sorunsuz olarak indiriliyor.
Servis sunan firma sorun olmadığını söylüyor. Zaten tarayıcıya dosya adını yazdığımda da hızlıca görüntüleniyor.
Bir şeyi atlıyor olmalıyım, ama ne ?
Bazen strStream := idhttp1.Get (F);
bazen de idHttp1.Get(F, MS); satırında takılıyor.
Bir çözüm olur mu diye
idHttp1.ReadTimeout := 10000;
idHttp1.RecvBufferSize := 250000;
idHttp1.AuthRetries := 10;
satırlarını ekledim ama nafile.
Kod: Tümünü seç
procedure BtnJpgDownloadClick(Sender: TObject);
var
F, Filename, strstream : string;
JPG : TJPEGImage;
BMP : TBitmap;
MS: TMemoryStream;
begin
idAntifreeze1.DoProcess;
Jpg := TJPEGImage.Create;
idHttp1 := TIdHTTP.Create(nil);
F := PRAdres;
FileName := 'downxx.JPG';
MS := TMemoryStream.Create;
try
idHttp1 := TIdHTTP.Create(nil);
idHttp1.ReadTimeout := 10000;
idHttp1.RecvBufferSize := 250000;
idHttp1.AuthRetries := 10;
try
strStream := idhttp1.Get (F);
except
on E: EIdHTTPProtocolException do
begin
ShowMessage(Format('İnternet bağlantısı yok : %d ', [idhttp1.ResponseCode]));
Exit;
end;
on E: EIdSocketError do
begin
ShowMessage('İnternet bağlantısı yok, daha sonra deneyin.');
Exit;
end;
on E: EIdConnectTimeout do
begin
ShowMessage('Bağlantı zaman aşımına uğradı, daha sonra deneyin');
PageControl1.ActivePage:=TabSheet1;
Exit;
end;
on E: EIdReadTimeout do
begin
ShowMessage('Bağlantı zaman aşımına uğradı, daha sonra deneyin');
PageControl1.ActivePage:=TabSheet1;
Exit;
end;
end;
try
idHttp1.Get(F, MS);
except
on E: EIdHTTPProtocolException do
begin
ShowMessage(Format('İnternet bağlantısı yok : %d ', [idhttp1.ResponseCode]));
Exit;
end;
on E: EIdSocketError do
begin
ShowMessage('İnternet bağlantısı yok, daha sonra deneyin.');
Exit;
end;
on E: EIdConnectTimeout do
begin
ShowMessage('Bağlantı zaman aşımına uğradı, daha sonra deneyin');
PageControl1.ActivePage:=TabSheet1;
Exit;
end;
on E: EIdReadTimeout do
begin
ShowMessage('Bağlantı zaman aşımına uğradı, daha sonra deneyin');
PageControl1.ActivePage:=TabSheet1;
Exit;
end;
end;
Application.ProcessMessages;
finally
idHttp1.Free;
end;
try
MS.Position := 0;
Jpg.LoadFromStream(MS);
PRImage.Picture.Assign(Jpg);
MS.Position := 0;
MS.SaveToFile(FileName);
Application.ProcessMessages;
finally
MS.Free;
end;
Bmp := TBitmap.Create;
try
Bmp.Assign(PrImage.Picture.Graphic);
SetStretchBltMode(PRImage1.Canvas.Handle, HALFTONE);
with Bmp do
PRImage1.Canvas.CopyRect(PRImage1.Canvas.ClipRect, Canvas, Canvas.ClipRect);
finally
Bmp.Free;
end;
end;