DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: xieqiongxi1
今日帖子: 0
在线用户: 5
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 yesin119 (yesin119) ★☆☆☆☆ -
盒子活跃会员
2016/3/18 9:13:17
标题:
Delphi使用idhttp怎么post一个UTF8编码xml格式的数据包? 浏览:1513
加入我的收藏
楼主: 用了好几个例子都不行:

sltmp := TStringlist.Create;
fsParams := TMemoryStream.Create;
try
  sltmp.Add(UTF8Encode
    ('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'));
  sltmp.Add(UTF8Encode('<Check>'));
  sltmp.Add(UTF8Encode('<TotalFee>10000</TotalFee>')); 
  sltmp.Add(UTF8Encode('<HotelCode>1841512343</HotelCode>'));
  sltmp.Add(UTF8Encode('<IdNumber>610300197123456789</IdNumber>'));
  sltmp.Add(UTF8Encode('<EncryptType>0</EncryptType>'));
  sltmp.Add(UTF8Encode('<IdType>0</IdType>'));
  sltmp.Add(UTF8Encode('<GuestName>程辉19920123</GuestName>'));
  sltmp.Add(UTF8Encode('<MobileNo>13180123454</MobileNo>')); 
  sltmp.Add(UTF8Encode('</Check>'));
  sltmp.SaveToStream(fsParams);
  idhtpSvr.Request.ContentType := 'text/xml';
  mmoXmlInfo.Text := idhtpSvr.Post(C_POST_URL, fsParams);   
  // 以post的方式发送到服务器
finally
  sltmp.Free;
  fsParams.Free;
end;

返回类似:
<br />
<b>Warning</b>:  simplexml_load_string(): Entity: line 8: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0xB3 0xCC 0xD0 0xA1 in <b>F:\web\alitrip.test\line\index.php</b> on line <b>5</b><br />
<br />
<b>Warning</b>:  simplexml_load_string():  in <b>F:\web\alitrip.test\line\index.php</b> on line <b>5</b><br />
<br />
<b>Warning</b>:  simplexml_load_string():          ^ in <b>F:\web\alitrip.test\line\index.php</b> on line <b>5</b><br />
<br />
<b>Fatal error</b>:  Call to a member function getName() on boolean in <b>F:\web\alitrip.test\line\index.php</b> on line <b>6</b><br />


貌似错误信息是说,Post的内容不是一个UTF8格式...
请教高手了.先谢过
----------------------------------------------
-
作者:
男 wang_80919 (Flying Wang) ★☆☆☆☆ -
普通会员
2016/3/18 9:23:21
1楼: fsParams := TStringStream(xmlStr,TEncoding.UTF8);
idhtpSvr.Request.ContentType := 'text/xml';
  mmoXmlInfo.Text := idhtpSvr.Post(C_POST_URL, fsParams);
----------------------------------------------
(C)(P)Flying Wang
作者:
男 yesin119 (yesin119) ★☆☆☆☆ -
盒子活跃会员
2016/3/18 9:57:10
2楼: 多谢楼上的
----------------------------------------------
-
作者:
男 olddelphier (oldDelphier) ▲▲▲▲△ -
普通会员
2016/3/18 12:48:49
3楼: sltmp.text:=ansitoutf8(sltmp.text);
idhttp1.pos('http://aaa/',sltmp);
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行59.81445毫秒 RSS