INDY http TIPS
指定URLの内容を取得する
with IdHttp1 do begin
S := Get('http://hogehoge/index.html');
end;
読み出し開始位置を設定する
with IdHttp1 do begin
Request.ContentRangeStart := 100; //100から読み込み
S := Get('http://hogehoge/index.html');
end;
Proxyを設定する
with IdHttp1 do begin
Request.ProxyServer := '172.16.1.1';
Request.ProxyPort := 8080;
Request.ProxyUsername := 'mona';
Request.ProxyPassword := 'saibaba';
end;
指定コンテンツのサイズを取得する
with IdHttp1 do begin
Head('http://hogehoge/index.html');
FSize := Response.ContentLength; // integer
end;
指定コンテンツの最終更新日を取得する
with IdHttp1 do begin
Head('http://hogehoge/index.html');
FDateTime := Response.LastModified; // TDateTime
end;
データをポストする
var
Res : TStringStream;
Source : TStringList;
begin
Res := TStringStream.Create('');
Source := TStringList.Create;
Source.Text := '送信内容';
try
try
FIdHttp.Post('http://hogehoge/write.cgi', Source, Res);
FContent := Res.DataString; //もどってきたHTML
except
//IdException
on E:EIdProtocolReplyError do
begin
if (E.ReplyErrorCode = 302) then begin
//正常終了
FContent := '';
end;
end
else raise;
end;
finally
Res.Free;
Source.Free;
end;
end;
クッキーを添えて送信する
FIdHttp.Request.ExtraHeaders.Add('Cookie:NAME=HOGEHOGE'); // こんなかんじ
FIdHttp.Post(Url, Source, Res);