All I get are some characters (4) everytime I want to get an image. I want to save an image with this command ./client example.com/image.jpg > img.jpg I think there is smth wrong with the recv at the end.
sprintf(request, "%s %s %s%s%s%s", "GET", path, "HTTP/1.1\r\n",
"HOST:", hostname, "\r\n\r\n");
//Send some data with TCP
if(send(sockfd, request, strlen(request), 0) < 0) {
printf("Send failed\n");
exit(1);
}
// printf("Request sended\n");
if(recv(sockfd, server_reply , sizeof(server_reply), 0) < 0) {//receive answer
printf("recv failed\n");
}
char *data = strstr(server_reply, "\r\n\r\n");//save data after header
data+=4;
//printf("Server reply: \n");//print the answer
puts(data);
close(sockfd);
return 0;
}
I think that I can't receive all image binary data but I don't know how to get everything correctly.