24,854
社区成员
发帖
与我相关
我的任务
分享
int CMainDlg::httpgzdecompress(BYTE *zdata, ULONG nzdata, BYTE *data, ULONG *ndata)
{
int err = 0;
z_stream d_stream = {};
static char dummy_head[2] =
{
0x8 + 0x7 * 0x10,
(((0x8 + 0x7 * 0x10) * 0x100 + 30) / 31 * 31) & 0xFF,
};
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = zdata;
d_stream.avail_in = 0;
d_stream.next_out = data;
if (inflateInit2(&d_stream, 47) != Z_OK) return -1;
while (d_stream.total_out < *ndata && d_stream.total_in < nzdata)
{
d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
if ((err = inflate(&d_stream, Z_NO_FLUSH)) == Z_STREAM_END)
break;
if (err != Z_OK)
{
if (err == Z_DATA_ERROR)
{
d_stream.next_in = (Bytef*)dummy_head;
d_stream.avail_in = sizeof(dummy_head);
if ((err = inflate(&d_stream, Z_NO_FLUSH)) != Z_OK)
{
return -1;
}
}
else return -1;
}
}
if (inflateEnd(&d_stream) != Z_OK) return -1;
*ndata = d_stream.total_out;
if (d_stream.total_in != nzdata)
err = Z_BUF_ERROR;
return err;
}
_variant_t varRspBody = pHttpReq->GetResponseBody();
ULONG dataLen = varRspBody.parray->rgsabound[0].cElements;
char *pContentBuffer = (char *)varRspBody.parray->pvData;
BYTE *btText = new BYTE[10000]();
ULONG ulLen = 10000;
httpgzdecompress((BYTE*)varRspBody.parray->pvData, dataLen, btText, &ulLen);
CString_Obj = (char*)btText;
delete btText;
为何最后显示的内容哦 显示不全 就是后面的全部显示为省略号了 我想获得全部的文本的话 应该怎么修改 求解决方案 谢谢int CMainDlg::httpgzdecompress(BYTE *zdata, ULONG nzdata, BYTE *data, ULONG *ndata, CString &strBody)
{
int err = 0;
z_stream d_stream = {};
static char dummy_head[2] =
{
0x8 + 0x7 * 0x10,
(((0x8 + 0x7 * 0x10) * 0x100 + 30) / 31 * 31) & 0xFF,
};
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = zdata;
d_stream.avail_in = 0;
d_stream.avail_out = 0;
d_stream.next_out = data;
if (inflateInit2(&d_stream, 47) != Z_OK) return -1;
while (d_stream.total_out < *ndata && d_stream.total_in < nzdata)
{
d_stream.avail_in = d_stream.avail_out = 1; // force small buffers
if ((err = inflate(&d_stream, Z_NO_FLUSH)) == Z_STREAM_END)
break;
if (err != Z_OK)
{
if (err == Z_DATA_ERROR)
{
d_stream.next_in = (Bytef*)dummy_head;
d_stream.avail_in = sizeof(dummy_head);
if ((err = inflate(&d_stream, Z_NO_FLUSH)) != Z_OK)
{
return -1;
}
}
else return -1;
}
}
if (inflateEnd(&d_stream) != Z_OK) return -1;
*ndata = d_stream.total_out;
CString strTemp(data);
ConvertUtf8ToGBK(strTemp);
strBody = strTemp;
if (d_stream.total_in != nzdata)
err = Z_BUF_ERROR;
return err;
}