Hi, I have the following code:
int http()
{
struct hostent *server;
struct sockaddr_in serv_addr;
int sockfd, bytes, sent, total, portno = 80;
char *host = "ejemplo.com";
char *message = "GET /scripts/newdate.php?nombre=test HTTP/1.1";
sockfd = socket(AF_INET, SOCK_STREAM, 0);
server = gethostbyname(host);
memset(&serv_addr,0,sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(portno);
memcpy(&serv_addr.sin_addr.s_addr,server->h_addr,server->h_length);
if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0)
error("ERROR connecting");
total = strlen(message);
sent = 0;
do {
bytes = write(sockfd,message+sent,total-sent);
if (bytes < 0)
error("ERROR writing message to socket");
if (bytes == 0)
break;
sent+=bytes;
} while (sent < total);
close(sockfd);
return 0;
}
and the code runs without problems but the request is not carried out (I know) it does not return any error or anything. Any idea what could happen?
According to the HTTP 1.1 protocol
Summary: you are missing 2
\r``\n
at the end of the application.As you show, the server is waiting forever for you to complete the request.