Idhttp Post 服务器接收不到数据,求原因
本帖最后由 jinlu7611 于 2013-04-19 10:14:37 编辑 小弟往服务器post 编码过的数据,结果服务器接收不到,不知道post的格式哪里不对了,求指点,代码如下
编码函数如下
AnsiString __fastcall URLEncodeT(AnsiString& inStr)
{
char hex[] = "0123456789ABCDEF";
AnsiString dst;
AnsiString src = inStr;
for (int i = 1; i <= src.Length(); ++i)
{
//ShowMessage(IntToStr(i));
char cc = src[i];
if(cc == ' ')
{
dst += '+';
}else if(cc >= 'A' && cc <= 'Z'){
dst += cc;
}else if(cc >= 'a' && cc <= 'z'){
dst += cc;
}else if(cc >= '0' && cc <= '9'){
dst += cc;
}else if(cc == '-' || cc == '.' || cc == '!'|| cc == '_' || cc == '~' || cc == '*' || cc == '\'' || cc == '(' || cc == ')' ){
dst += cc;
}else{
char c = static_cast<unsigned char>(src[i]);
dst += '%';
dst += hex[c / 16];
dst += hex[c % 16];
}
}
return dst;
}
Url = "http://172.21.4.138:8080/UnionUpdate/UnionUpdateService";
ClientVersion = "KABW900+_CH.2.02.002";
request = "<?xml version="1.0" encoding="utf-8"?><Request><RequestType>mobileVersion</RequestType><MobileVersionParams><OpType>verifyRom</OpType><ClientVersion>"+ClientVersion+"</ClientVersion><RomSize>12345678</RomSize><UserName></UserName><SystemOuterVersion></SystemOuterVersion><FileType>img</FileType><CustomizationType>cmcc</CustomizationType><Paramater1></Paramater1><Paramater2></Paramater2><Paramater3></Paramater3></MobileVersionParams><OtherParams></OtherParams></Request>";
AnsiString sa = URLEncodeT(request);
TStringList *params = new TStringList();
AnsiString param = "param";
params->Add((param+"="+sa));
TStringStream *returnString=new TStringStream("");
try
{
IdHTTP1->Post(Url,params,returnString);
}
catch(...)
{
ShowMessage("服务器连接错误,无法检测升级包的合法性!");
}
delete params;
delete returnString;