|
|
导航: |
论坛 -> 网络通讯
斑竹:liumazi,sephil |
|
作者: |
|
2012/5/24 16:26:35 |
标题: |
delphi XE2 indy10.5.8 IdHTTPServer 中文乱码...求助 |
浏览:3533 |
|
加入我的收藏 |
楼主: |
服务端: procedure TForm1.IdHTTPServerCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo); var sText: string; begin // ARequestInfo.ContentEncoding := 'utf-8'; //ARequestInfo.Params.DefaultEncoding := TEncoding.UTF8; ARequestInfo.CharSet := 'UTF-8'; sText := getnow + '' + '' + AContext.Connection.Socket.Binding.PeerIP + ':' + Inttostr(AContext.Connection.Socket.Binding.PeerPort) + ' ' + '' + ARequestInfo.Document + ',parms=' + ARequestInfo.Params.GetText; if ckbResp.Checked then begin AResponseInfo.ContentText := edtSend.Text; AResponseInfo.WriteContent; end; Memo1.Lines.Add(sText); end;
客户端 procedure TFrmClient.btnSendClick(Sender: TObject); const url = 'http://%s:%s%s'; var sUrl, sText: string; AStr: TStringStream; begin sUrl := Format(url, [edtHost.Text, edtPort.Text, edtSend.Text]); sText := getnow + ' ' + sUrl; Memo1.Lines.Add(sText); Application.ProcessMessages;
IdHTTP.Request.AcceptEncoding := 'utf-8'; IdHTTP.Response.ContentEncoding := 'utf-8'; AStr := TStringStream.Create('', TEncoding.UTF8); IdHTTP.Request.ContentType := 'text/html;Charset=UTF-8'; IdHTTP.Get(sUrl, AStr); if (AStr.DataString <> '') then begin sText := getnow + '' + '' + edtHost.Text + ':' + edtPort.Text + ' ' + AStr.DataString; Memo1.Lines.Add(sText); end; AStr.Free; end;
现在是客户端发送相关内容过去.英文没问题,出现中文,,就会中文部分就变成???? 服务端也一样.收不到中文,只要有中文就显示???? 请朋友知道的.帮忙解决 下.
----------------------------------------------
- |
作者: |
star5 (星五) |
★☆☆☆☆ |
-
|
盒子活跃会员 |
|
2012/5/24 16:49:40 |
1楼: |
ansitoutf8
----------------------------------------------
博客 - http://offeu.com 脚本模型 - http://webpascal.com 需要短信接口的请联系我,可发行业与营销内容。
|
作者: |
|
2012/5/24 16:50:42 |
2楼: |
1楼的朋友..我是在xe2 下,默认就是utf-8..
----------------------------------------------
-
|
作者: |
|
2012/5/26 23:32:41 |
3楼: |
xe2默认是unicode
----------------------------------------------
-Delphi是毒,一旦染上,很难戒掉。
|
|