RT...!!写了一个去操作网页的软件.``! 模拟人工发包``! 有个地方``post请求后.返回的是个302重定向..! 当然我用的 CHttpCFile 这个类里的SendRequest成员来处理的..! 网上查过资料..! 这个函数能直接处理重定向跳转``!!直接返回重定向之后的页面
最后``他返回的是这么一串数据..
1f8b0800000000000400edbd07601c499625262f6dca7b7f4af54ad7e074a10880601324d8904010ecc188cde692ec1d69472329ab2a81ca6556655d661640cced9dbcf7de7befbdf7de7befbdf7ba3b9d4e27f7dfff3f5c6664016cf6ce4adac99e2180aac81f3f7e7c1f3f227ee3e4f1effaf4cb9337bfcfcbd374de2ecaf4e5574f9e9f9da41f6ddfbdfbdd7b2777ef3e7df334fdbdbffde68be7e9ee78277d5367cba6688b6a999577ef9ebef828fd68deb6ab4777ef5e5d5d8dafee8dabfae2ee9b5777df01d62e5ed65fb75befcdf1ac9d7d74445de3abf4dda25c369f45e0ec3e7cf8505e97c67936c3cf45de66846bbbdace7fd1bab8fceca3936ad9e6cb76fbcdf52aff289dca5f9f7dd4e6efdabb78fb309dceb3bac9dbcfd6edf9f6c147e95d80298be5dbb4a557b4e5b4693e4ae7757e6e51b918cf8bab6249ff1b4fab051adc9d1559595d8ce9d78fd23a2f3ffba869afcbbc99e779ab60dba22df3a3fff2effd2bffcbbff7afff2ffed43ffe3ffbfbffbcc777e533faf2ae19c3a49a5de3e7acb84ca765d6d0f8db62f5fb13a806634de9f9cfffc6bffb3ffbbbfef8ffea6fff3bffc7bfef8ffb2fffd6bff7bffc7bffc2fffa0ffe23fff33fea6ffacffe9e3fe23ffbbbfea0ffeceffa6bfe8b3fec4ffccfffb23fe3bffc73feb0fffa4ffbb3ffabbff16f246884de25bdcd5019b1cf3e5a65b359b1bcd86eabd5a3fb3bab778702fe71b15caddb74992da8cd45552d896e82c6a45dfefe7b1f296126ebb6c577c5ccb4aa96d3b298be05e09aa83c9e5527eb766febe38fef1c7e945e66e59adefa2fffe2bfe13fff1bfe1ca587c1e9ae19324fc9d16f9cfc3ff1fdaf8a7a020000
返回的数据是我直接从内存里拿出来的`````我试过UTF8``UNICODE``ANSI编码..!! 怎么都不对..!!
以下是我的代码..!
JQString JQtools;
char* chBuff = JQtools.ToAnsi((LPWSTR)(LPCWSTR)Post);
UINT len = strlen(chBuff);
pFile-> SendRequest(NULL,0,chBuff, len);
pFile->QueryInfoStatusCode(retcode);
if (retcode == HTTP_STATUS_OK)
{
CString m_strHtml;
JQString strtools;
char szBuff[0x10000];
memset(szBuff,0,0x10000);
UINT outlen = 0;
UINT nRead;
CString strTmp;
while ((nRead = pFile->Read(szBuff,0x9000))>0)
{
/*for(int i = 0; i < nRead; i++)
{
if(0x00 == (byte)szBuff[i])
{
szBuff[i] = 0x20;
}
}*/
strTmp += szBuff;
memset(szBuff,0,0x10000);
}
另外补充下..!!``单步过 pFile->QueryInfoStatusCode(retcode); retcode 值是200;
nRead = pFile->Read(szBuff,0x9000))>0; nRead 值是617; 也就是接收到的实际长度
szBuff 缓冲区里面``我开的是0x10000的数组..!! 返回的就是上面的数据`` ``求大神告知..!
只有这么多分了..!
------解决思路----------------------
我贴一部分代码吧, 网页的一般没有头, 需要自己添加头(代码的 bzRepair )
zlib的用法你必须要自己去学会用
static BOOL DeCompress(DAT_INPUT_PROC fnDatIn, DAT_OUTPUT_PROC fnOut, VOID *pUserParam)
{
z_stream zstream;
BOOL bRetVal;
BYTE bzBuffer[4096];
BYTE bzBufferOut[4096];
int nRead, nOutSize;
int nError;
BOOL bRepair;
BYTE bzRepair[2] = {0x78, 0x01};
bRepair = FALSE;
memset(&zstream, 0, sizeof(z_stream));
nError = inflateInit2(&zstream, GZIP_BIT);
// nError = inflateInit2(&zstream, DEF_WBITS);
if(nError < 0)
{
ATLTRACE("inflateInit error: %d\n", nError);
return FALSE;
}
for(;;)
{
if(zstream.avail_in == 0)
{
bRetVal = fnDatIn(bzBuffer, sizeof(bzBuffer), &nRead, pUserParam);
zstream.next_in = bzBuffer;
zstream.avail_in = nRead;
}
zstream.next_out = bzBufferOut;
zstream.avail_out = sizeof(bzBufferOut);
nError = inflate(&zstream, Z_SYNC_FLUSH);
if(nError == Z_DATA_ERROR)
{
bRepair = TRUE;
inflateReset(&zstream);
zstream.next_in = bzRepair;
zstream.avail_in = sizeof(bzRepair);
nError = inflate(&zstream, Z_NO_FLUSH);
zstream.next_in = bzBuffer;
zstream.avail_in = nRead;
zstream.next_out = bzBufferOut;
zstream.avail_out = sizeof(bzBufferOut);
nError = inflate(&zstream, Z_SYNC_FLUSH);
}
nOutSize = sizeof(bzBufferOut) - zstream.avail_out;
if(bRepair && zstream.avail_in == 0 && nOutSize == 0)
break;
if(nOutSize)
bRetVal = fnOut(bzBufferOut, nOutSize, pUserParam);
if(nError < 0)
{
ATLTRACE("inflate error: %d\n", nError);
return FALSE;
}
if(nError == Z_STREAM_END)
break;
}
nError = inflateEnd(&zstream);
if(nError < 0)
{
ATLTRACE("inflateEnd error: %d\n", nError);
return FALSE;
}
return TRUE;
}