刚才我通过连接编写HTML内容没有问题。
sprintf(toreturn, "%s\r\n%s\r\n%s\r\n\r\n%s", "HTTP/1.1 200 OK", "Content-Type: text/html", "Connection: close",htmlstring);
write(*inputfd, toreturn, strlen(toreturn))
哪个工作正常。但这就是我试图传递图像以响应图像请求的原因。在这种情况下,它适用于.ico
文件,但我的问题代表任何二进制文件。
FILE *writefile = (FILE *)calloc(1,sizeof(FILE));
char *charptr = inputaddress;
charptr++;
writefile=fopen(charptr,"r");
sprintf(toreturn, "%s\r\n%s\r\n%s\r\n\r\n", "HTTP/1.1 200 OK", "Content-Type: image/vnd.microsoft.icon", "Connection: close");
write(*inputfd, toreturn, strlen(toreturn))
write(*inputfd, *writefile, strlen(toreturn)
close(*inputfd);
fclose (writefile);
这是行不通的。如何write()
在 C 中通过 HTTP 生成图像(或任何二进制文件)文件?