유닉스 c로 간단한 프로그램을 짜고 있는 초보 입니다.
현재 유닉스 C에서 post방법으로 웹페이지를 호출하여 웹페이지에 로그를 남기는 프로그램을 만들구 있습니다.
그러나 계속 405 에러가 나네요..;;
소켓생성...
서버연결요청...
----오류내용 -------------------------------------------
서버로부터 : HTTP/1.1 405 Method not allowed
Server: Microsoft-IIS/5.0
Date: Mon, 15 Mar 2010 08:05:01 GMT
Allow: OPTIONS, TRACE, GET, HEAD
Content-Length: 3815
Content-Type: text/html
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
< html dir=ltr>
< head>
.
.
.
@@ 유닉스 C 에서 작성한 프로그램 http_post5.c
#include
#include
#include
#include
#include
#include
#include
void error_handling(char *message);
int main( int argc, char **argv)
{
int sock;
int str_len, i;
struct sockaddr_in serv_addr;
char msg1[] ="par=9";
// char msg2[] =" I am so happy!!!";
char message[1024];
char buff[1024*2];
//버퍼 초기화 2048
memset(buff, 0x00, sizeof(buff));
// 소켓생성
sock= socket(PF_INET, SOCK_STREAM, 0);
printf("소켓생성...\n");
if( sock == -1)
error_handling("socket() error ");
memset(&serv_addr , 0 , sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr("210.109.111.214");
serv_addr.sin_port= htons(80);
// 서버 연결요청
printf("서버연결요청...\n");
if( connect(sock,(struct sockaddr*) &serv_addr, sizeof(serv_addr)) == -1)
error_handling("connect error");
sprintf(buff, "POST /test/print.jsp HTTP/1.0\r\n"
"User-agent: Mozilla\r\n"
"Referer: http://210.109.111.214:80 /test\f\c_http4.asp\r\n"
"Content-type: application/x-www-form-urlencoded\r\n"
"Content-length: %d\r\n"
"\r\n%s\r\n",
strlen(msg1), msg1);
write(sock, buff, strlen(buff));
for( i = 0 ; i < 100 ; i++)
{
str_len = read(sock , message , sizeof(message) -1);
message[str_len]= 0;
printf("서버로부터 : %s \n", message );
}
close(sock);
return 0;
}
void error_handling(char *message)
{
fputs(message, stderr);
fputc('\n' , stderr);
exit(1);
}
@@ 웹페이지 소스 ASP 입니다.
<%
str_tmp = request.Form("param")
write_log(" log now is jun param : "& str_tmp &" " & Year(now)&Month(now)&Day(now)&"("&now&")")
'response.write "
end " & now
Sub write_log(str)
Set fs2 = Server.CreateObject("Scripting.FileSystemObject")
Set objFile2 = fs2.OpenTextFile("D:\cpupload\test\f\c_http_log4.txt",8,true)
objFile2.writeLine(str)
objFile2.close
End Sub
%>
@@ PS.
혹시 UNIX C상에서 post방식으로 웹페이지 호출할려면 다른 방법이 있을까요?
아님 제가 한방식에 문제가 있는것인지 유닉스 C 고수님들 좀 봐주세요~