Delphi | Получить ответ от NetHTTPRequest

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by Bonkеrs, 30 Oct 2017.

  1. Bonkеrs

    Bonkеrs Member

    Joined:
    5 Feb 2014
    Messages:
    26
    Likes Received:
    13
    Reputations:
    3
    Кидаем на форму компонент TNetHTTPRequest, отправляем запрос NetHTTPRequest1.Get('http://ya.ru');

    Как получить response?
     
  2. Bonkеrs

    Bonkеrs Member

    Joined:
    5 Feb 2014
    Messages:
    26
    Likes Received:
    13
    Reputations:
    3
    Code:
    function TForm1.GetResponse(aURL: string): string;
    var
      stream: TStringStream;
    begin
      with NetHTTPClient1 do
      begin
        AllowCookies := true;
        try
          stream := TStringStream.Create('', TEncoding.UTF8);
          Get(aURL, stream);
          Result := stream.DataString;
        finally
          FreeAndNil(stream);
        end;
      end;
    end;
     
Loading...