Autor Beitrag
FrankBurian
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 57



BeitragVerfasst: Mo 29.05.06 17:04 
Hallo.

Ich greife mit idHttp.Get(...) (Indy) auf eine HTML-Seite zu.
Gibt es eine Möglichkeit der Seite die ich aufrufe(auslese) einen bestimmten Referer vor zu gauckeln?
Das heißt wenn die HTML-Seite ein PHP-Script ist was den Referer(Herkunftsseite) ausliest und darstellt, das es dann zum Beispiel eine URL meiner wahl ausgibt?

Danke
MfG
SAiBOT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 323
Erhaltene Danke: 6

XP SP2; 7
D7; D2009
BeitragVerfasst: Di 30.05.06 22:00 
Ja, retnyg hat mal eine Unit gemacht! (spitzen ding)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure DL(Filename:String);
var
  http:THttpGetRec;
begin
  http.URL           := 'http://dl.romhustler.net/snes/'+FileName+'.7z';
  http.URL           := StringReplace(http.URL, ' ''%20', [rfreplaceall]);
  http.Referer       := 'http://romhustler.net/download/snes/';
  http.Agent         := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
  http.BinaryData    := True;
  http.FileName      := 'C:\'+FileName+'.7z';
  retHttpGet.HttpGetFile(http);
end;


Unit: (krazz.net/retnyg/)
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
unit retHttpGet;

interface

uses windows, wininet, sysutils;

type

   PHttpGetRec = ^THttpGetRec;
   THttpGetRec = record
     AcceptTypes: String;
     Agent: String;
     BinaryData: Boolean;
     URL: String;
     UseCache: Boolean;
     FileName: String;
     FileSize: integer;
     UserName: String;
     Password: String;
     PostQuery: String;
     Referer: String;
     StringResult: String;
   end;

   function HttpGetFile   (var T: ThttpGetRec):boolean;
   function HttpGetString (var T: ThttpGetRec):boolean;

implementation

function HttpGet (var T: ThttpGetRec; ToFile: boolean): boolean;
var
  hSession, hConnect, hRequest: hInternet;
  HostName, FileName: String;
  f: File;
  Buf: Pointer;
  dwBufLen, dwIndex: DWord;
  Data: String;
  TempStr: String;
  RequestMethod: PChar;
  InternetFlag: DWord;
  AcceptType: LPStr;
  BytesToRead, BytesReaded: DWord;

  procedure ParseURL(URL: Stringvar HostName, FileName: String);

    procedure ReplaceChar(c1, c2: Char; var St: String);
    var
      p: Integer;
    begin
      while True do
       begin
        p := Pos(c1, St);
        if p = 0 then Break
        else St[p] := c2;
       end;
    end;

  var
    i: Integer;
  begin
    if Pos('http://', LowerCase(URL)) <> 0 then
      System.Delete(URL, 17);

    i := Pos('/', URL);
    HostName := Copy(URL, 1, i);
    FileName := Copy(URL, i, Length(URL) - i + 1);

    if (Length(HostName) > 0and (HostName[Length(HostName)] = '/'then
      SetLength(HostName, Length(HostName) - 1);
  end;

 procedure CloseHandles;
 begin
   InternetCloseHandle(hRequest);
   InternetCloseHandle(hConnect);
   InternetCloseHandle(hSession);
 end;

begin
  try
    SetLength(Data, $400);

    ParseURL(T.URL, HostName, FileName);

    if T.Agent <> '' then
     hSession := InternetOpen(PChar(T.Agent),
       INTERNET_OPEN_TYPE_PRECONFIG, nilnil0)
    else
     hSession := InternetOpen(nil,
       INTERNET_OPEN_TYPE_PRECONFIG, nilnil0);

    hConnect := InternetConnect(hSession, PChar(HostName),
      INTERNET_DEFAULT_HTTP_PORT, PChar(T.UserName), PChar(T.Password), INTERNET_SERVICE_HTTP, 00);

    if T.PostQuery = '' then RequestMethod := 'GET'
    else RequestMethod := 'POST';

    if T.UseCache then InternetFlag := 0
    else InternetFlag := INTERNET_FLAG_RELOAD;

    AcceptType := PChar('Accept: ' + T.AcceptTypes);
    hRequest := HttpOpenRequest(hConnect, RequestMethod, PChar(FileName), 'HTTP/1.0',
                PChar(T.Referer), @AcceptType, InternetFlag, 0);

    if T.PostQuery = '' then
     HttpSendRequest(hRequest, nil0nil0)
    else
     HttpSendRequest(hRequest, 'Content-Type: application/x-www-form-urlencoded'47,
                     PChar(T.PostQuery), Length(T.PostQuery));


    dwIndex  := 0;
    dwBufLen := 1024;
    GetMem(Buf, dwBufLen);

    Result := HttpQueryInfo(hRequest, HTTP_QUERY_CONTENT_LENGTH,
                              Buf, dwBufLen, dwIndex);

    if Result or not T.BinaryData then
     begin
      if Result then
        T.FileSize := StrToInt(StrPas(Buf));

      BytesReaded := 0;

      if ToFile then
       begin
        AssignFile(f, T.FileName);
        Rewrite(f, 1);
       end
      else T.StringResult := '';

      while True do
       begin

        if not InternetReadFile(hRequest, @Data[1], Length(Data), BytesToRead) then Break
        else
         if BytesToRead = 0 then Break
         else
          begin
           if ToFile then
            BlockWrite(f, pointer(Data)^, BytesToRead)
           else
            begin
             TempStr := Data;
             SetLength(TempStr, BytesToRead);
             T.StringResult := T.StringResult + TempStr;
            end;

           inc(BytesReaded, BytesToRead);
{           if Assigned(FTProgress) then
            Synchronize(UpdateProgress); }

// add progress code here if needed            
          end;
       end;

      if ToFile then
        Result := T.FileSize = Integer(BytesReaded)
      else
       begin
        SetLength(T.StringResult, BytesReaded);
        Result := BytesReaded <> 0;
       end;

      if ToFile then CloseFile(f);
     end;

    FreeMem(Buf);

    CloseHandles;
  except
  end;
end;

procedure SetupVars(var T: THttpGetRec);
begin
  if T.AcceptTypes = '' then T.AcceptTypes := '*/*';
  if T.Agent = '' then T.Agent := 'Mozilla 4.0 (retnyg rulez 1.337)';
end;

function HttpGetFile   (var T: ThttpGetRec):boolean;
begin
   SetupVars(T);
   if HttpGet(T, true) then result := true else result := false;
end;

function HttpGetString (var T: ThttpGetRec):boolean;
begin
   SetupVars(T);
   if HttpGet(T, false) then result := true else result := false;
end;


end.
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mi 31.05.06 16:59 
da du ja die INDY Http Kompo verwnedest, kannst du den Referrer einfach unter Request.Referrer setzen !

_________________
In the beginning was the word.
And the word was content-type: text/plain.