|
소켓 프로그램으로 http 페이지를 호출하는 소켓프로그램은 구현을 했는데요..
https 페이지를 소켓프로그램으로 호출할려고 하니...
당장 막막한 느낌이 들어서요.
접근하는 방식부터 막혀서 헤메고 있습니다.
혹시 아래 소스를 보시고
https 페이지를 호출하는 소켓프로그램 작성에 도움주실분들은 연락주시기 바랍니다..
------------
http페이지를 소켓프로그램으로 호출하는 C module
------------
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main()
{
char *str;
int sockfd, numbytes;
char buf[1024];
struct hostent *he;
struct sockaddr_in their_addr;
char *strurl;
char *url_directory;
char *host_name;
int lenurl;
str = (char *) malloc (sizeof(char) * 512);
host_name = (char *) malloc (sizeof(char) * 100);
strurl = (char *) malloc (sizeof(char) * 100);
url_directory = (char *) malloc (sizeof(char) * 100);
/* URL 문자열 입력 */
strcpy(host_name,"dic.simmani.com"); // URL
strcpy(url_directory,"/cgi-bin/search.cgi"); // URL Directory
strcpy(str,"query=test"); // parameter
if ((he = gethostbyname(host_name)) == NULL) {
herror("gethostbyname");
return 1;
}
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("socket");
return 1;
}
their_addr.sin_family = AF_INET;
their_addr.sin_port = htons(80);
their_addr.sin_addr = *((struct in_addr *)he->h_addr);
bzero(&(their_addr.sin_zero), 8);
if (connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1) {
perror("connect");
return 0;
}
/* HTTP/1.1 프로토콜로 URL 호출 */
sprintf(strurl, "POST %s HTTP/1.1\n",url_directory);
send(sockfd, strurl, strlen(strurl), 0);
strcpy(strurl, "Content-Type: application/x-www-form-urlencoded\n");
send(sockfd, strurl, strlen(strurl), 0);
strcpy(strurl, "Accept-Encoding:gzip, deflate\n");
send(sockfd, strurl, strlen(strurl), 0);
sprintf(strurl, "Host: %s\n",host_name);
send(sockfd, strurl, strlen(strurl), 0);
sprintf(strurl, "Content-Length: %d\n\n", strlen(str));
send(sockfd, strurl, strlen(strurl), 0);
send(sockfd, str, strlen(str), 0);
/* 정상적으로 URL을 호출하였나 찍는 부분 */
while( recv(sockfd, buf, 1024, 0) > 0)
printf("%s\n",buf);
close(sockfd);
}
|