|
|
导航: |
论坛 -> 网络通讯
斑竹:liumazi,sephil |
|
作者: |
mit (.﹎筷樂) |
★☆☆☆☆ |
-
|
普通会员 |
|
2011/2/10 23:54:49 |
标题: |
Delphi xe 使用IDHTTP问题 |
浏览:8055 |
|
加入我的收藏 |
楼主: |
我使用的是Delphi XE.没有打update1补丁. INDY还是10.5.7版本. 在IDHTTP.POST后结果为乱码. 在先前使用的Delphi2010中设置idhttp.response.charset:='gb2312'; 就可以解决了. 但在XE中无法解决,请问在哪里可以正确设置字符编码呢? 请教...
----------------------------------------------
- |
作者: |
|
2011/2/11 2:29:45 |
1楼: |
POST之前 选择好编码 stream可以设置初始化编码了
idhttp.response.charset:='gb2312'; 这个只是文字表达
----------------------------------------------
-
|
作者: |
star5 (星五) |
★☆☆☆☆ |
-
|
盒子活跃会员 |
|
2011/2/11 8:17:00 |
2楼: |
var vResponse: TStringStream;//返回值的编码 vParam:TStringList;//post参数 begin { gb2312=936,gb18030=54936,utf8=65001 } vParam.Create; vResponse := TStringStream.Create('', TEncoding.GetEncoding(936)); try idhttp.request.charset:='gb2312';//指定编码 vParam.Add('id=test'); vParam.Add('pwd=123456'); idhttp.Post('http://www.没定拆哪.com', vParam, vResponse); showmessage(vResponse.DataString); finally vParam.free; vResponse.free; end; end;
----------------------------------------------
博客 - http://offeu.com 脚本模型 - http://webpascal.com 需要短信接口的请联系我,可发行业与营销内容。
|
作者: |
star5 (星五) |
★☆☆☆☆ |
-
|
盒子活跃会员 |
|
2011/2/11 8:18:08 |
3楼: |
vResponse这个是用来指定返回值的编码,idhttp.request.charset是用来指定提交的编码,都有用的。
----------------------------------------------
博客 - http://offeu.com 脚本模型 - http://webpascal.com 需要短信接口的请联系我,可发行业与营销内容。
|
作者: |
ljf (梵) |
★☆☆☆☆ |
-
|
盒子活跃会员 |
|
2011/2/11 11:01:48 |
4楼: |
procedure TForm1.Button4Click(Sender: TObject);
var ss: TStringStream; begin idhttp1.ReadTimeout := 30000; idhttp1.Request.Accept := 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*'; idhttp1.Request.AcceptLanguage := 'zh-cn'; idhttp1.Request.ContentType := 'application/x-www-form-urlencoded'; idhttp1.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)'; ss := TStringStream.Create('', TEncoding.GetEncoding(936)); // 指定gb2312的中文代码页,或者54936(gb18030)更好些 utf8 对应 65001 // 俄文的CODEPAGE为 1251或866 到时自己测试 try // idhttp1.Get('hhttp://tieba.baidu.com', ss); idhttp1.Get('http://www.2ccc.com', ss); mmo1.Text := ss.DataString; finally ss.Free; end; // mmo1.Lines.Text := idhttp1.Get('http://tieba.baidu.com/'); end;
----------------------------------------------
-
|
作者: |
mit (.﹎筷樂) |
★☆☆☆☆ |
-
|
普通会员 |
|
2011/2/11 21:11:13 |
5楼: |
谢谢了!
----------------------------------------------
-
|
作者: |
|
2013/10/31 15:04:41 |
6楼: |
delphiXE中解决中文下载问题,需要把Url编码fileurl :=idHTTP.URL.URLEncode(fileurl);
----------------------------------------------
aaa
|
作者: |
|
2015/12/25 23:43:20 |
7楼: |
转一个解决方案,经测试有效。
1. 发过去的是乱码如下处理, 服务器采用的是UFT-8编码的情况下 uses HTTPApp; sPost := HTTPEncode(UTF8Encode('中文POST数据'));
2. 返回的是乱码如下处理 ResponseStream:=TStringstream.Create('',TEncoding.UTF8); idhttp.Post(ConnectUrl,sends,ResponseStream);
希望对LZ有帮助。
----------------------------------------------
喜欢Delphi,关注Delphi,愿和广大爱好者交朋友。
|
|