![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
проблема с загрузкой файлов через TIdHTTP [D7, Win2k]
hbreaker © (2006-06-16 17:32:00)вот есть у меня такая процедура, должна скачивать файл и сохранять его в temp каталоге. Но почему-то выскакивает такое сообщение при вызове fIdHTTP.Get
Project Photoportal.exe raised exception class EConvertError with message ''' is not a valid integer value'. Process stopped. Use Step or Run to continue.
procedure TGetPhotosThread.GetPhoto(photo_id:integer);
var
strm: TFileStream;
s: string;
begin
try
strm := TFileStream.Create(temp+inttostr(photo_id)+'.jpg',fmCreate);
s := ' http://photoportal.dream.ua/soap/get_photo.php?session='+session+'&id='+inttostr(photo_id);
fIdHTTP.Get(s);
strm.CopyFrom(fIdHTTP.Response.ContentStream,fIdHTTP.Response.ContentStream.Size );
finally
strm.Free;
end;
end;
fIdHTTP создается в конструкторе класса
constructor TGetPhotosThread.Create(_photos: PhotosStructArray; _temp: string; _session:string);
begin
inherited Create(True);
photos := _photos;
temp := _temp;
session := _session;
fIdHTTP := TIdHTTP.Create(nil);
Resume; // запустить
end;
hbreaker (2006-06-19 18:23:00) [1]нашел такую функцию, которая использует только WinInet + может работать через проки.
uses WinInet;
function DownloadFile(const FileURL, FileName: String): Cardinal;
var
hSession, hFile: HInternet;
Buffer: array[1..1024] of Byte;
BufferLen, fSize: LongWord;
f: File;
begin
Result := 0;
hSession := InternetOpen(’STEROID Download’,
INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(hSession) then
begin
hFile := InternetOpenURL(hSession, PChar(FileURL), nil, 0,
INTERNET_FLAG_RELOAD, 0);
if Assigned(hFile) then
begin
AssignFile(f, FileName);
Rewrite(f,1);
fSize := 0;
repeat
InternetReadFile(hFile, @Buffer, SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen);
fSize := fSize + BufferLen;
until (BufferLen = 0);
CloseFile(f);
Result := fSize;
InternetCloseHandle(hFile);
end;
InternetCloseHandle(hSession);
end;
end;
Всё работает:))
Slym (2006-06-19 05:24:00) [2]закачка по маске?
смотри почту...
hbreaker (2006-06-16 18:32:00) [3]IdHTTP.Get(s, strm)
пробовал тоже самое... думал так будет:)
если не idhttp то чем ещё можно?
может.. как-то на сокетах. но если нада через прокси.. я пока не умею. где можно найти инфу на эту тему?
Dmitrij_K (2006-06-16 18:28:00) [4]Инди плохо реагирует на нестандартный заголовок, как-то давно пришлось в коде idhttp try exceptписать, т.к. сервер давал данные не в том формате
Dmitrij_K (2006-06-16 18:22:00) [5]Первое, почему не IdHTTP.Get(s, strm)
Второе, ошибка в самом инди, пользуйся отладчиком и смотри где строка в число преобразуется
hbreaker (2006-06-16 18:20:00) [6]в смысле длина photo_id равна нулю ?
у меня строка s нормально формируется. ошибка когда идет вызов fIdHTTP.Get(s);
tesseract (2006-06-16 18:09:00) [7]
> inttostr(photo_id)
Здесь error, когда длина photo_id равна нулю, его нельзя преобразовывать в integer.