Показать сообщение отдельно
  #7  
Старый 08.01.2013, 09:47
Аватар для PhoeniX
PhoeniX PhoeniX вне форума
Always hardcore!
 
Регистрация: 04.03.2009
Адрес: СПб
Сообщения: 3,239
Версия Delphi: GCC/FPC/FASM
Репутация: 62149
По умолчанию

Цитата:
Сообщение от Pcrepair
и еще, с HTTPs это будет как то работать?
Код:
 
function LoadFileHTTPS(server, url: WideString): WideString;
begin
var
  hInet, hConn, hReq: Pointer;
  buf: array of char;
  bufSize, bufRead, p: cardinal;
begin
  hInet := WinHttpOpen('UserAgent/1.0',0,nil,nil,0);
  hConn := WinHttpConnect(hInet, PWideChar(server), INTERNET_DEFAULT_HTTPS_PORT, 0); // HTTP -> HTTPS
  hReq := nil;
  repeat
    if hReq <> nil then WinHttpCloseHandle(hReq);
    repeat hReq := WinHttpOpenRequest(hConn, 'GET', PWideChar(url), 'HTTP/1.1', nil, nil, WINHTTP_FLAG_SECURE) until hReq <> nil;
    // Флаг WINHTTP_FLAG_SECURE
    while not WinHttpSendRequest(hReq, nil, 0, nil, 0, 0, 0) do;
  until WinHttpReceiveResponse(hReq, nil);
  bufSize := 0;
  p := 0;
  while WinHttpQueryDataAvailable(hReq, bufSize) do begin
    SetLength(buf,p+bufSize);
    if bufSize = 0 then break;
    bufRead := 0;
    WinHttpReadData(hReq, @buf[p], bufSize, bufRead);
    inc(p,bufRead);
  end;
  WinHttpCloseHandle(hReq);
  WinHttpCloseHandle(hConn);
  WinHttpCloseHandle(hInet);
  SetLength(buf,p+1);
  Result := UTF8Decode(UTF8String(PChar(@buf[0])));
end;
 
procedure TForm1.Button1Click(Sender: TButton);
begin
  MessageBoxW(0,PWideChar(LoadFileHTTPS('github.com','/')),nil,0);
end;
__________________
Оставайтесь хорошими людьми...
VK id2634397, ds [at] phoenix [dot] dj
Ответить с цитированием