옛날에 동아리 클럽에 썼던 글입니다.
============================================================================================
1. 함수 원형
2. 인자 설명
nPort : 포트번호
nQuery : 쿼리 횟수
3. 헤더 파일
- wininet.h (?)
4. 함수 코드
{
/*
Return -1 : 포트번호입력오류
Return 2 : InternetOpen() 함수에러
Return 3 : InternetConnect() 함수에러
Return 4 : HttpOpenRequest() 함수에러
Return 0 : 정상
*/
if(nPort<=0 || nPort>65535)
{
return -1;
}
HINTERNET hIOpen = InternetOpen(“TestWeb”,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
if ( hIOpen == NULL )
return 2;
UINT i;
for(i=0;i
{
HINTERNET hIConnect = InternetConnect(hIOpen,szAddress,nPort,NULL,NULL,INTERNET_SERVICE_HTTP, 0, 0);
if ( hIConnect == NULL )
{
InternetCloseHandle(hIOpen);
return 3;
}
// Request the file from the server.
//LPCTSTR ppszAcceptTypes = “text/*” ;
HINTERNET hIReq = HttpOpenRequest(hIConnect,
NULL, // “Get”
NULL,
(LPCSTR)HTTP_VERSION,
NULL, //(LPCSTR )csUrlCon,
NULL,//&ppszAcceptTypes,
INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
0);
if ( hIReq == NULL){
InternetCloseHandle(hIConnect);
InternetCloseHandle(hIOpen);
return 4;
}
// Send the request.
HttpSendRequest(hIReq, NULL, 0, NULL, 0);
BYTE pBuffer[8192]={0,};
DWORD dwBytesRead;
InternetReadFile(hIReq,pBuffer,8192,&dwBytesRead);
// Close all of the Internet handles.
InternetCloseHandle(hIReq);
InternetCloseHandle(hIConnect);
}
InternetCloseHandle(hIOpen);
}
==========================================================================================================================
BSD용으로(리눅스&OSX) 변환 연습해봐야지,,,