Send binary file in HTTP response using C sockets

前端 未结 4 1611
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 06:44

I`m trying to send a binary file (png image) in http response.

FILE *file;
char *buffer;
int fileLen;

//Open file
file = fopen(\"1.png\", \"rb\");
if (!file         


        
4条回答
  •  误落风尘
    2020-12-10 07:14

    I tried to follow what you did but could not get it to work. Instead, I found it easier to just send header and file separately.

    e.g.

    send(client, header, strlen(header), 0);
    send(client, buffer, fileLen + 1, 0);
    

提交回复
热议问题