I am having an issue sending information to my browser on a valid request.
This is the header file we create on a valid file, printed out to the console.
Message:
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 139
Connection: Close
0�5
My socket is set up to listen, and here's my valid request code:
Code:
int return_result(int fd, char *content_type, char *buf, int numbytes) {
FILE *fp;
fp=fdopen(fd, "w+");
if (fp==NULL) {
perror("Couldn't open file");
return -1;
}
char* message;
message=malloc(sizeof(char)*MSGSIZE+sizeof(buf));
int count=sprintf(message, "HTTP/1.1 200 OK\n\rContent-Type: %s\n\rContent-Length: %d\n\rConnection: Close\n\n%s\n\r",content_type, numbytes, &buf);
printf("Message:\n%s\n",message);
write(fd, message, strlen(message));
fflush(fp); //flush
close(fp);
return 0;
I don't know what I'm doing wrong.
Thanks for any help.