我无法在基于 C 的代理中显示图像
I can't get images to display in my C based proxy
因此,我正在尝试创建一个基于C的代理系统,并且很难阅读通过连接的图像数据。我可以大部分时间访问页面,但是当我尝试将图像数据从服务器发送回浏览器时,我看不到图像。以下是用于从服务器接收数据的代码,然后将消息发送到浏览器。我希望有人能有一个线索可以帮助我,谢谢!*代理阻止奇数字节内容显示,这是那里的代码的一部分,但是我要加载的图像甚至是字节#。
do {
//Receive message from server
bytes = recv(clientsockfd, messagein, MAX_MESSAGE_LENGTH, 0);
if(bytes > 0)
strncpy(messageout,messagein,bytes);
else if(bytes == 0) {
printf("nConnection closedn");
strcpy(messageout,"HTTP/1.1 200 OKrnrn");
}
printf("Answer received from server: n");
printf("%snnTotal Bytes: %dnn", messagein, bytes);
//Copy the messagein to a tempStr so we can leave original message untouched
strncpy(tempStr,messagein,bytes);
//Check to see if the content is even or odd only if the message in has a content length field, later we will determine if we do anything with it
if(strstr(messagein,"Content-Length:") != NULL)
evenContent = checkContent(tempStr);
//If the content is odd then we want to change the message we'll send back to the browser
if(!evenContent) {
//If the page is odd then I redirect the user to carey's error page he made
if(strstr(messagein,"text/html") != NULL)
strcpy(messageout,"HTTP/1.1 302 FoundrnLocation: http://pages.cpsc.ucalgary.ca/~carey/CPSC441/errorpage.htmlrnrn");
else if(strstr(messagein,"image/") != NULL) {
//If the image is odd then I just send back empty data to the browser
strcpy(messageout,"HTTP/1.1 200 OKrnrn");
}
}
#ifdef DEBUG
printf("nnAbout to send message to the web browser:n%s",messageout);
#endif
/* send the result message back to the browser */
send(childsockfd, messageout, bytes, 0);
/* initialize message strings just to be safe (null-terminated) */
for( i = 0; i < MAX_MESSAGE_LENGTH; i++ )
{
messagein[i] = ' ';
messageout[i] = ' ';
tempStr[i] = ' ';
}
} while (bytes != 0);
您在此处假设通过单个呼叫recv
一起获得标题和内容。但是对于可能不正确的大要求,图像通常很大)。要进行解析,您应该致电recv
,直到您进行解析为止,包括内容长度,然后致电recv
,直到收到内容长度的字节。
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 代理对象的常量正确性
- 字符串-C++后显示的随机字符
- 继承期间显示未知行为的子类
- 仅使用绝对值对数组进行排序,并在C++中显示实际值
- 程序崩溃并显示"std::out_of_range"错误
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- 从数据库实时显示QT c++中的数据
- 当使用比格式支持的精度更高的精度来显示数字时,会写出什么数据
- 显示错误输出的简单数组排序程序
- Qt自定义QPush按钮未显示在布局上
- C++射线示踪剂ppm表示没有足够的数据来显示图像
- 显示基于用户输入的整数的字符
- 使用QTreeView,如何通过调用函数只突出显示特定的行/列
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- 我无法在基于 C 的代理中显示图像