|
C语言示例直接调用 openSite(全映射域名); 进行完成认证,其它语言类同
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <unistd.h>
- int openSite(char *argv){
-
- int sockfd;
- int len;
- struct sockaddr_in address;
- int result;
- char httpstring[100];
- sprintf(httpstring,"GET / HTTP/1.1\r\n"
- "Host: %s\r\n"
- "Connection: Close\r\n\r\n",argv);
- char ch;
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- address.sin_family = AF_INET;
- address.sin_addr.s_addr = inet_addr(argv);
- address.sin_port = htons(8080);
- len = sizeof(address);
- result = connect(sockfd,(struct sockaddr *)&address,len);
- if(result == -1){
- perror("oops: client");
- return 1;
- }
- write(sockfd,httpstring,strlen(httpstring));
- while(read(sockfd,&ch,1)){
- printf("%c", ch);
- }
- close(sockfd);
- printf("\n");
- return 0;
- }
复制代码
|
|