忽略通过 HTTP GET C++ 接收的字符缓冲区中的转义字符
Ignoring escape characters in a char buffer received through HTTP GET C++
我正在发送从网页获取图像的请求。
我将 C++ 与 winsocket 和 tcp http get 请求一起使用。
我在 char 缓冲区中收到所有信息,但是当我将它流式传输到文件或字符串时,它非常短,因为其中有字符串终止符。
best/most 处理转义字符的有效方法是什么?
提前致谢。
编辑:
流出("temp.jpg");
//m_Received.reserve(STRINGBUFFERSIZE);
char rBuffer[BUFFERSIZE];
int readSize = 0;
int totalSize = 0;
do
{
PRINT("Reset buffer");
ZeroMemory(rBuffer, sizeof(rBuffer));
PRINT("Receiving...");
readSize = recv(socket, rBuffer, sizeof(rBuffer), 0);
PRINT("Received " << readSize << " bytes...");
if (readSize > 0)
{
totalSize += readSize;
//m_Received.append(rBuffer);
for (int i = 0; i < readSize; ++i)
{
out << rBuffer[i];
}
if (readSize < BUFFERSIZE)
{
PRINT("Stopping receiving...");
break;
}
}
else if (readSize == -1)
throw SocketError("ErrorReceiving", readSize);
} while (readSize > 0);
即使单独放置每个字符,我也会发现与原始图像的微小差异,这会导致损坏。
好的,所以我通过简单地将 char 缓冲区二进制文件写入我的文件来修复它。早该想到这一点。
我正在发送从网页获取图像的请求。 我将 C++ 与 winsocket 和 tcp http get 请求一起使用。 我在 char 缓冲区中收到所有信息,但是当我将它流式传输到文件或字符串时,它非常短,因为其中有字符串终止符。 best/most 处理转义字符的有效方法是什么?
提前致谢。
编辑: 流出("temp.jpg");
//m_Received.reserve(STRINGBUFFERSIZE);
char rBuffer[BUFFERSIZE];
int readSize = 0;
int totalSize = 0;
do
{
PRINT("Reset buffer");
ZeroMemory(rBuffer, sizeof(rBuffer));
PRINT("Receiving...");
readSize = recv(socket, rBuffer, sizeof(rBuffer), 0);
PRINT("Received " << readSize << " bytes...");
if (readSize > 0)
{
totalSize += readSize;
//m_Received.append(rBuffer);
for (int i = 0; i < readSize; ++i)
{
out << rBuffer[i];
}
if (readSize < BUFFERSIZE)
{
PRINT("Stopping receiving...");
break;
}
}
else if (readSize == -1)
throw SocketError("ErrorReceiving", readSize);
} while (readSize > 0);
即使单独放置每个字符,我也会发现与原始图像的微小差异,这会导致损坏。
好的,所以我通过简单地将 char 缓冲区二进制文件写入我的文件来修复它。早该想到这一点。