Hello
OS: RedHat Linux
I have to write a c program that should issue an HTTP GET request such as the following:
localhost/seo/test_tal.php?val=2 (The script updates a row
in the database table)
I tried using socket for that on port 80.
I used functions:
1) sockfd = socket(PF_INET, SOCK_STREAM, 0)
2) connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct
sizeof(struct sockaddr))
3) bytes_sent = send(sockfd, msg, len, 0) ; // msg contains the http
headers get request
The code:
The problem is that the bytes are sent but the script test_tal.php
is not activated.
Thanks
Yehuda
OS: RedHat Linux
I have to write a c program that should issue an HTTP GET request such as the following:
localhost/seo/test_tal.php?val=2 (The script updates a row
in the database table)
I tried using socket for that on port 80.
I used functions:
1) sockfd = socket(PF_INET, SOCK_STREAM, 0)
2) connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct
sizeof(struct sockaddr))
3) bytes_sent = send(sockfd, msg, len, 0) ; // msg contains the http
headers get request
The code:
Code:
void http_socket() {
int sockfd ;
struct sockaddr_in dest_addr ;
int len, bytes_sent ;
char *msg = malloc(MAXDATASIZE) ;
// do some error checking!
if (sockfd = socket(PF_INET, SOCK_STREAM, 0) == ERROR_NUMBER) {
printf("Socket error\n") ;
exit(1) ;
}
dest_addr.sin_family = AF_INET ; // host byte order
dest_addr.sin_port = htons(MYPORT) ; // short, network byte order, MYPORT=80
dest_addr.sin_addr.s_addr = inet_addr(DEST_IP) ;
memset(&(dest_addr.sin_zero), '\0', 8) ; // zero the rest of the struct
// don't forget to error check the connect()!
if ( connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)) == ERROR_NUMBER) {
exit(1) ;
}
bytes_sent = 0 ;
strcpy(msg, "[URL unfurl="true"]http://localhost/seo/test_tal.php?val=2[/URL] ") ;
//strcat(msg, "HTTP/1.0") ;
len = strlen(msg) ;
bytes_sent += send(sockfd, msg, len, 0) ;
printf("Bytes sent = %i\n", bytes_sent) ;
free(msg) ;
}
The problem is that the bytes are sent but the script test_tal.php
is not activated.
Thanks
Yehuda