想用CHttpFile读取网页,然后写到txt里面,但是网页是经过压缩的,我就用zlib库里面的uncompress函数解压,但是怎么都不行,函数返回是 Z_DATA_ERROR 表示是 the input data was corrupted.,就是需要转换的数据损坏,但是我的数据是直接从网上接受的啊,不知道哪里错了,请高人看一下,代码如下: pFile->AddRequestHeaders("Accept-Encoding: gzip,deflate\t\n");
pFile->AddRequestHeaders("Accept-Language: zh-CN\t\n");
pFile->AddRequestHeaders("Connection: Keep-Alive\t\n");
ret=pFile->SendRequest();
CString revd;
DWORD StatusCode;
pFile->QueryInfoStatusCode(StatusCode);
CString login;
if(StatusCode == HTTP_STATUS_OK)
{
while (pFile->ReadString(login))
{
revd += login;
}
}
char *source = revd.GetBuffer(0);
char *dest = new char[revd.GetLength()+1];
memset(dest,0,revd.GetLength()+1);
uLong len = 0;
int ret = uncompress((unsigned char *)dest,&len,(unsigned char *)source,revd.GetLength());
if(ret == Z_MEM_ERROR)
AfxMessageBox("there was not enough memory");
if(ret == Z_BUF_ERROR)
AfxMessageBox("there was not enough room in the output buffer");
if(ret == Z_DATA_ERROR)
AfxMessageBox("the input data was corrupted");
pFile->AddRequestHeaders("Accept-Language: zh-CN\t\n");
pFile->AddRequestHeaders("Connection: Keep-Alive\t\n");
ret=pFile->SendRequest();
CString revd;
DWORD StatusCode;
pFile->QueryInfoStatusCode(StatusCode);
CString login;
if(StatusCode == HTTP_STATUS_OK)
{
while (pFile->ReadString(login))
{
revd += login;
}
}
char *source = revd.GetBuffer(0);
char *dest = new char[revd.GetLength()+1];
memset(dest,0,revd.GetLength()+1);
uLong len = 0;
int ret = uncompress((unsigned char *)dest,&len,(unsigned char *)source,revd.GetLength());
if(ret == Z_MEM_ERROR)
AfxMessageBox("there was not enough memory");
if(ret == Z_BUF_ERROR)
AfxMessageBox("there was not enough room in the output buffer");
if(ret == Z_DATA_ERROR)
AfxMessageBox("the input data was corrupted");
---------------------------
不要这一行,返回的数据不就不需要解码了吗?