idhttp怎样get网站的图片文件?[
{
如果Get验证码完成后要获取Cookie 就这样做:idhtp1.Response.RawHeaders.GetText; //关键行
idhtp1.Response.RawHeaders.Text;//都是一样的效果;
或者 idhtp1.CookieManager.CookieCollection.Items[0].CookieText 但是后者通常都会出错。应该还需要添加idCookieManager控件与idhttp关联。
}
{
403错误:服务器要判断浏览器类别在GET之前,先指定UserAgent参数就行了.
Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Maxthon)';
}
procedure TForm1.Button1Click(Sender: TObject);
var imagestream:TMemoryStream;
jpg :TJpegImage;
bmp:TBitMap;
str:string;
begin
str:= 'http://10.113.58.5/oa_case/office/images/b1.jpg ';
try
IdHTTP1.Connect;
except
showmessage( '连接出错 ');
Exit;
end;
imagestream:=TMemoryStream.Create;
IdHTTP1.Get(str,imagestream);
imagestream.Position:=0;
//如果是bmp图片
if Copy(str,LastDelimiter( '. ',str)+1,4)= 'bmp ' then
begin
bmp:=TBitmap.Create;
bmp.LoadFromStream(imagestream);
Image1.Picture.Assign(bmp);
end;
//如果是jpg图片
if Copy(str,LastDelimiter( '. ',str)+1,4)= 'jpg ' then
begin
jpg:=TJPEGImage.Create;
jpg.LoadFromStream(imagestream);
Image1.Picture.Assign(jpg);
end;
end;