idhttp co robie źle?

0
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP;

type
  TForm2 = class(TForm)
    IdHTTP1: TIdHTTP;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

const
VOID = '';

function Explode(Ch: Char; s: string; Index: Byte): string;
type
  TTableString = array of string;

  function InternalExplode(Str: string; Divider: Char): TTableString;
  var
    i, j: Integer;
  begin
    j := 1;
    i := 1;
    while i <= Length(Str) do
    begin
      if (Str[i] = Divider) or (i = Length(Str)) then
      begin
        if (i = Length(Str)) and (Str[i] <> Divider) then
          Inc(i);
        SetLength(Result, High(Result) + 2);
        Result[High(Result)] := Trim(Copy(Str, j, i - j));
        j := i + 1;
      end;
      Inc(i);
    end;
  end;
begin
  Result := InternalExplode(s, ch)[index];
end;

procedure TForm2.Button1Click(Sender: TObject);
var
source: String;
answer: TStringStream;
result: String;
begin
source:='/appsvc/appmsg_ver8.asp?fmnumber=1234567&fmt=&lastmsg=1&version=8.0.0.7669';
answer:=TStringStream.Create(VOID);
IdHTTP1.ProtocolVersion:=pv1_1;
IdHTTP1.Request.Host:='appmsg.gadu-gadu.pl';
IdHTTP1.Request.AcceptLanguage:='pl';
IdHTTP1.Request.ContentType:='application/x-www-form-urlencoded';
IdHTTP1.Request.UserAgent:='Mozilla/4.0 (compatible; MSIE 5.0; Windows NT)';
IdHTTP1.Request.Pragma:='no-cache';
IdHTTP1.Get(source, answer);
IdHTTP1.Free;
answer.Free;
result := answer.DataString;
if result[Length(result)] = #10 then
   Delete(result, Length(result), 1);
if result = 'notoperating' then
   result := VOID
else
   result := Explode(' ', result, 3);
end;

end.

Program się kompiluje i na końcu wywala error "Unknown protocol." Co robię nie tak? Kod praktycznie w całości "zerżnąłem" z HGG więc tym bardziej mnie to dziwi ;/

0

Nie wiem czy to jest glowna przyczyna ale najpierw robisz

answer.free

, potem odwolujesz sie do answer.DataString

0
zibicider napisał(a)

Nie wiem czy to jest glowna przyczyna ale najpierw robisz

answer.free

, potem odwolujesz sie do answer.DataString



noo przeciez tak jest...
0

Ciekawe... od kiedy to mozna sie odwolywac do zniszczonego obiektu ?

0
lordi156 napisał(a)

Program się kompiluje i na końcu wywala error "Unknown protocol." Co robię nie tak? Kod praktycznie w całości "zerżnąłem" z HGG więc tym bardziej mnie to dziwi ;/

Miałem ten sam problem gdy próbowałem zaciągnąć HGG do Turbo Delphi 2006.
Najprawdopodobniej wynika to z użytych wersji INDY.

Ja u siebie zrobiłem tak :

begin
  HTTP := TIdHTTP.Create(nil);
  Source := 'http://'+C_HTTP_SERVER_HOST+C_HTTP_SERVER_SOURCE;
  Result := HTTP.Get(Source);
  HTTP.Free;
  if Result[Length(Result)] = #10 then
    Delete(Result, Length(Result), 1);
  if Result = 'notoperating' then
    Result := VOID
  else
    Result := Explode(' ', Result, 3);
end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1