c socket 发送http请求
2010年04月15日
c socket 发送http请求
#include
#include
#include
#include
#include
#include
int main(){
int sockfd;
int len;
struct sockaddr_in address;
int result;
char *strings="GET /svnup/rewrite.php HTTP/1.1\r\nHost: 192.168.1.12\r\nConnection: Close\r\n\r\n";
char ch;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr("192.168.1.12");
address.sin_port = htons(80);
len = sizeof(address);
result = connect(sockfd, (struct sockaddr *)&address, len);
if(result == -1){
perror("oops: client1");
return 1;
}
write(sockfd,strings,strlen(strings));
while(read(sockfd,&ch,1))
printf("%c", ch);
close(sockfd);
return 1;
}
2010年04月15日
c socket 发送http请求
#include
#include
#include
#include
#include
#include
int main(){
int sockfd;
int len;
struct sockaddr_in address;
int result;
char *strings="GET /svnup/rewrite.php HTTP/1.1\r\nHost: 192.168.1.12\r\nConnection: Close\r\n\r\n";
char ch;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr("192.168.1.12");
address.sin_port = htons(80);
len = sizeof(address);
result = connect(sockfd, (struct sockaddr *)&address, len);
if(result == -1){
perror("oops: client1");
return 1;
}
write(sockfd,strings,strlen(strings));
while(read(sockfd,&ch,1))
printf("%c", ch);
close(sockfd);
return 1;
}