现在的位置: 首页 > 综合 > 正文

HTTP POST数据时,一定要将数据转换为UTF8再调用HttpSendRequest!!!

2019年03月19日 ⁄ 综合 ⁄ 共 692字 ⁄ 字号 评论关闭

问题:POST一个页面如http://127.0.0.1/post.php HTTP body为user=aaa&pass=bbb时,INTERNET_BUFFERS的dwBufferLength返回正确的长度17,但是lpReadBuff有时为空,有时为乱码

崩溃了,MSDN上看到这句话。。。

[code=html]Note  The HttpSendRequestA function represents headers as ISO-8859-1 characters not ANSI characters. The HttpSendRequestW function represents headers as ISO-8859-1 characters converted to UTF-16LE characters. As a result, it is never safe to use
the HttpSendRequestW function when the headers to be added can contain non-ASCII characters. Instead, an application can use the MultiByteToWideChar and WideCharToMultiByte functions with a Codepage parameter set to 28591 to map between ANSI characters and
UTF-16LE characters. [/code]
当时没细看这段话,原来我POST的字符串定义的是unicode,一定要转换成UTF8再调用HttpSendRequest!!!!错误诡异的很啊!!!

抱歉!评论已关闭.