Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   С/С++, C#, Delphi, .NET, Asm (https://forum.antichat.xyz/forumdisplay.php?f=24)
-   -   [wininet] помогите неразумному((( (https://forum.antichat.xyz/showthread.php?t=203818)

RedFern.89 13.05.2010 20:58

[wininet] помогите неразумному(((
 
при передачи файла на сервер, программа виснет! Код процедуры:

Код:

function UploadFileToServer(aurl: string; FileName: string): boolean;
var
  hSession      : hInternet;
  hConnect      : hInternet;
  hRequest      : hInternet;
  hFile          : THandle;
  RequestFlags  : DWORD;
  Sum            : DWORD;
  dwBytesRead    : DWORD;
  dwBytesWritten : DWORD;
  pBuffer        : DWORD;
  bRead, bRet    : boolean;
  BufferIn      : INTERNET_BUFFERS;
  _post, Headers,
  boundary      : string;
begin
  boundary := '--------' + FormatDateTime('mmddyyhhnnsszzz ', Now); { not localize }
 _post := 'note=vk&font1=decor&font2=20&orient=h&size1=x&size2=1024x768&rotate=00&flip=0&mini=300x225&opt3[]=zoom&email=';

  headers := 'Content-Type: multipart/form-data; boundary=' + boundary;

  pBuffer := 1024;
  hSession := InternetOpen('Delphi/7.0', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);

  hConnect := InternetConnect(hSession, PChar(GetHost(AUrl)), 80, nil, nil,
                              INTERNET_SERVICE_HTTP, 0, 0);

  RequestFlags := INTERNET_FLAG_NO_CACHE_WRITE or  INTERNET_FLAG_KEEP_CONNECTION;

  hRequest := HttpOpenRequest(hConnect, 'POST', '/index.php', 'HTTP/1.1', nil, nil,
                              RequestFlags, 0);

  hFile := CreateFile(PChar(FileName), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

  ZeroMemory(@BufferIn, SizeOf(BufferIn));
  BufferIn.dwStructSize := SizeOf(INTERNET_BUFFERS);
  BufferIn.dwBufferTotal := GetFileSize(hFile, nil);
  BufferIn.lpcszHeader := PChar(Headers);
  BufferIn.dwHeadersLength := Length(Headers);

  HttpSendRequestEx(hRequest, @BufferIn, nil, HSR_INITIATE, 0);

  Sum := 0;
  bRead := True;
  bRet := True;

  repeat
    bRead := ReadFile(hFile, pBuffer, SizeOf(pBuffer), dwBytesRead, nil);
    bRet := InternetWriteFile(hRequest, @pBuffer, dwBytesRead, dwBytesWritten);
    sum := sum + dwBytesWritten;
  until dwBytesRead = SizeOf(pBuffer);


 HttpEndRequest(hRequest, nil, 0, 0);

  CloseHandle(hFile);
  InternetCloseHandle(hSession);
  InternetCloseHandle(hConnect);
  InternetCloseHandle(hRequest);   
end;


AlexTheC0d3r 13.05.2010 21:07

скорее всего цикл
Цитата:

repeat
bRead := ReadFile(hFile, pBuffer, SizeOf(pBuffer), dwBytesRead, nil);
bRet := InternetWriteFile(hRequest, @pBuffer, dwBytesRead, dwBytesWritten);
sum := sum + dwBytesWritten;
until dwBytesRead = SizeOf(pBuffer);
бесконечный

RedFern.89 13.05.2010 21:10

закоментил строку HttpEndRequest(hRequest, nil, 0, 0); и виснуть перестало. Однако запрос не передается по нормальному.


Время: 08:16