mc******@brainsquash.org (Mike Chirico) wrote in message news:<ad**************************@posting.google. com>...
For a C http_post example ref:
http://souptonuts.sourceforge.net/code/http_post.c.html
Regards,
Mike
#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>
#define SA struct sockaddr
#define MAXLINE 4096
/* Following could be derived from SOMAXCONN in <sys/socket.h>, but many
kernels still #define it as 5, while actually supporting many more */
#define LISTENQ 1024 /* 2nd argument to listen() */
void process_http(FILE *fp, int sockfd){
char sendline[MAXLINE], recvline[MAXLINE];
ssize_t n;
strcpy(sendline,"POST /test.php HTTP/1.0\r\n");
strcat(sendline,"Host: souptonuts.sourceforge.net\r\n");
strcat(sendline,"Content-type: application/x-www-form-urlencoded\r\n");
strcat(sendline,"Content-length: 34\r\n\r\n");
strcat(sendline,"mode=login&user=test&password=tes t\r\n");
write(sockfd, sendline, strlen(sendline));
while ( ( n = read(sockfd, recvline, MAXLINE)) != 0 )
{
recvline[n]='\0';
fprintf(stderr,"%s",recvline);
}
/* Interesting note: if you want to see how many
reads there are through the while loop do a
# tcpdump src port 80
And the size of n will be the mss, value in ( ) from this
call
*/
}
int
main(int argc, char **argv)
{
int sockfd;
struct sockaddr_in servaddr;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(80);
inet_pton(AF_INET, "66.35.250.209", &servaddr.sin_addr);
connect(sockfd, (SA *) &servaddr, sizeof(servaddr));
process_http(stdin, sockfd);
exit(0);
}
Mike Chirico