拖三个组件: memo ,idhttp,edit 加一个Button
然后在procedure TForm1.Button1Click(Sender: TObject);里加上一句话
1.可以这么写
memo1.Text:= idHTTP1.Get(edit1.Text);
2.也可以这么写
memo1.Lines.Add(IdHTTP1.Get(edit1.Text));
这件事就这么简单.
不过,别用它来试百度,因为百度屏蔽了 ‘Indy Library’ 这个客户端标识的。
hehe,除非修改http头
User-Agent: Mozilla/3.0 (compatible; Indy Library) 修改前面绿色的部分
注:如果出现的是乱码,查一下html的文件头,看看编码方式,然后比如改成这样
memo1.Text:=utf8toansi( idHTTP1.Get(edit1.Text));
更进一步:
function TForm1.Get(URL: string):string;
var
IDHTTP: TIDHttp;
ss: String;
begin
IDHTTP:= TIDHTTP.Create(nil);
try
try
idhttp.Disconnect;
idhttp.HandleRedirects:= true; //必须支持重定向否则可能出错
idhttp.ReadTimeout:= 30000; //超过这个时间则不再访问
ss:=utf8toansi( IDHTTP.Get(URL)); //UTF8编码转换
// if ss='' then
ss:=UTF8Decode(idhttp.Get(url));
if IDHTTP.ResponseCode=200 then
Result :=ss;
except
//ss:='';
end;
finally
IDHTTP.Free;
end;
end;
http://hi.baidu.com/sxshandian/blog/item/96d217d6339adb2806088b22.html
LNMP 1.6 常见的502问题解决
关于贴图看不到。显示是白色或者其他。
windows 任务栏图标宽度固定
Install Oracle Java JDK/JRE 7u55 on Fedora 20/19, CentOS/RHEL 6.5/5.10
盘点天龙历史:七年以来所有资料片
linux shell 逻辑运算符、逻辑表达式详解
vim 把满足条件的数字进行加上一些数字
win7 一些快捷系统工具命令
Linux下用C读取配置文件。类似ini这样。