openURL("http://XXX.XXX.XXX/user?user=sunshine&message=中文测试")
服务器发送的消息都是“.....”
而我在IE的地址栏中“http://XXX.XXX.XXX/user?user=sunshine&message=中文测试”服务器却可以发送的消息“中文测试”。
请指点一下,谢谢
chinese string has to be encoded before send to http server
IE does it automatically, while you have to do it in your program.
http://codeguru.earthweb.com/cpp_mfc/URLEncode.html
你必须首先转换成unicode或者utf-8的
BOOL
CADlg::DoUrlEncode(CString csSrcData, CString &csDstData)
{
long lngLength;
long lngPos;
char chSrc;
LPCTSTR strSrc;
char *strEr;
CString csHexCode;
CString csSource;
csSource.Empty();
lngLength = csSrcData.GetLength();
strSrc = (LPCTSTR)csSrcData;
for (lngPos = 0; lngPos < lngLength; lngPos++) {
chSrc = *(strSrc + lngPos);
if (chSrc != %) {
csSource += chSrc;
} else {
if (lngPos + 2 < lngLength) {
csHexCode.Empty();
csHexCode += *(strSrc + (++lngPos));
csHexCode += *(strSrc + (++lngPos));
csSource += (unsigned char)strtoul(csHexCode, &strEr, 16);
if (*strEr != 0) {
//throw(cderException);
return 0;
};
} else {
//throw(cderException);
return 0;
};
};
};
//AfxMessageBox( csSource );
csDstData = csSource;
//if (IsJisConvert) {
// csSrc = csSource;
// ConvJisToSJis();
// csSource = csDst;
//};
return 0;
}
UTF-8