본문 바로가기
VisualStudio.C++.C#

win api . WinHTTP . http clinet api . C/C++

by i.got.it 2022. 1. 24.

WinHTTP C/C++ windows API 개요

 

- 윈도우 운영체제에 기본 포함된 C/C++ API .  파일명 : winhttp.dll

- 윈도우 8 이후 부터 웹소켓 연결 설정 함수도 추가됨 .

  - - 웹소켓 함수 예 : WinHttpWebSocketSend ,  WinHttpWebSocketReceive

 

- 현재(2022.03) 최신 버전  5.1  . 버전 5.0 은 2004년 10월 1일 부터 MS 사에서 배포 종료됨. 

 

 

WinHTTP 에서 제공되는 함수 전체 

 

WinHTTP는 다음과 같은 함수를 제공합니다.

 

 

WinHttpAddRequestHeaders

HTTP 요청 핸들에 하나 이상의 HTTP 요청 헤더를 추가합니다.

 

WinHttpAddRequestHeadersEx

HTTP 요청 핸들에 하나 이상의 HTTP 요청 헤더를 추가하여 별도의 이름/값 문자열을 사용할 수 있습니다.

 

WinHttpCheckPlatform

현재 플랫폼이 WinHTTP에서 지원되는지 여부를 결정합니다.

 

WinHttpCloseHandle

단일 HINTERNET 핸들을 닫습니다.

 

WinHttpConnect

HTTP 요청의 초기 대상 서버를 지정합니다.

 

WinHttpCrackUrl

URL을 해당 구성 요소 부분(예: 호스트 이름 및 경로)으로 구분합니다.

 

WinHttpCreateProxyResolver

WinHttpGetProxyForUrlEx에서 사용할 핸들을 만듭니다.

 

WinHttpCreateUrl

구성 요소 부분(예: 호스트 이름 및 경로)에서 URL을 만듭니다.

 

WinHttpDetectAutoProxyConfigUrl

PAC(프록시 자동 구성) 파일의 URL을 찾습니다. 이 함수는 PAC 파일의 URL을 보고하지만 파일을 다운로드하지는 않습니다.

 

WinHttpFreeProxyResult

WinHttpGetProxyResult에 대한이전 호출에서 검색된 데이터를 확보합니다.

 

WinHttpFreeQueryConnectionGroupResult

WinHttpQueryConnectionGroup에 대한 이전 호출에서 할당한 메모리를 해제합니다.

 

WinHttpGetDefaultProxyConfiguration

레지스트리에서 기본 WinHTTP 프록시 구성을 검색합니다.

 

WinHTTPGetIEProxyConfigForCurrentUser

현재 사용자에 대한 IE(Internet Explorer) 프록시 구성을 가져옵니다.

 

WinHttpGetProxyForUrl

지정된 URL에 대한 프록시 정보를 검색합니다.

 

WinHttpGetProxyForUrlEx

지정된 URL에 대한 프록시 정보를 검색합니다.

 

WinHttpGetProxyResult

WinHttpGetProxyForUrlEx에 대한호출 결과를 검색합니다.

 

WinHttpOpen

애플리케이션의 WinHTTP 함수 사용을 초기화합니다.

 

WinHttpOpenRequest

HTTP 요청 핸들을 만듭니다.

// WinHttpOpenRequest 함수인자중 3번째것. 서버메인주소 뒷부분을 기록함.

WinHttpOpenRequest(hConnect, L"POST", L"/path/to/myFile.html", ... 

WinHttpOpenRequest(hConnect, L"POST", L"/", ... // 서버메인페이지의 것으로 요청할때

 

 

 

WinHttpQueryAuthSchemes

서버에서 지원하는 권한 부여 체계를 반환합니다.

 

WinHttpQueryConnectionGroup

WinHttp 연결의 현재 상태에 대한 설명을 검색합니다.

 

WinHttpQueryDataAvailable

WinHttpReadData로 즉시 읽을 수 있는 데이터의 바이트 수를 반환합니다.

 

WinHttpQueryHeaders

HTTP 요청과 연결된 헤더 정보를 검색합니다.

 

WinHttpQueryHeadersEx

HTTP 요청과 연결된 헤더 정보를 검색합니다. 는 구문 분석된 헤더 이름 및 값 문자열을 검색하는 방법을 제공합니다.

 

WinHttpQueryOption

지정된 핸들에서 인터넷 옵션을 쿼리합니다.

 

WinHttpReadData

WinHttpOpenRequest 함수가 연 핸들에서 데이터를 읽습니다.

 

WinHttpReadDataEx

WinHttpOpenRequest 함수가 연 핸들에서 데이터를 읽습니다.

 

WinHttpReceiveResponse

WinHttpSendRequest에 의해 시작된 HTTP 요청을 종료합니다.

 

WinHttpResetAutoProxy

자동 프록시를 다시 설정합니다.

 

WinHttpSendRequest

지정된 요청을 HTTP 서버로 보냅니다.

 

WinHttpSetCredentials

필요한 권한 부여 자격 증명을 서버에 전달합니다.

 

WinHttpSetDefaultProxyConfiguration

레지스트리에서 기본 WinHTTP 프록시 구성을 설정합니다.

 

WinHttpSetOption

인터넷 옵션을 설정합니다.

 

WinHttpSetStatusCallback

작업 중에 진행이 수행되면 WinHTTP에서 호출할 수 있는 콜백 함수를 설정합니다.

 

WinHttpSetTimeouts

HTTP 트랜잭션과 관련된 다양한 시간 아웃을 설정합니다.

 

WinHttpTimeFromSystemTime

HTTP 버전 1.0 사양에 따라 날짜 및 시간의 서식을 지정합니다.

 

WinHttpTimeToSystemTime

HTTP 시간/날짜 문자열을 가져와서 SYSTEMTIME 구조체로 변환합니다.

 

WinHttpWriteData

HTTP 서버에 요청 데이터를 씁니다.

 

WinHttpWebSocketClose

WebSocket 연결을 닫습니다.

 

WinHttpWebSocketCompleteUpgrade

WinHttpSendRequest에서시작한 WebSocket 핸드셰이크를 완료합니다.

 

WinHttpWebSocketQueryCloseStatus

서버에서 보낸 닫기 상태를 가져옵니다.

 

WinHttpWebSocketReceive

WebSocket 연결에서 데이터를 받습니다.

 

WinHttpWebSocketSend

WebSocket 연결을 통해 데이터를 보냅니다.

 

WinHttpWebSocketShutdown

WebSocket 연결에 닫기 프레임을 보냅니다.

 

from :  https://docs.microsoft.com/ko-kr/windows/win32/winhttp/winhttp-functions

 

 

 

코드 예 

 

#pragma comment(lib, "Winhttp.lib")
#include <Winhttp.h>



DWORD dwSize = 0;
    DWORD dwDownloaded = 0;
    LPSTR pszOutBuffer;
    BOOL  bResults = FALSE;
    HINTERNET  hSession = NULL, 
               hConnect = NULL,
               hRequest = NULL;

    // Use WinHttpOpen to obtain a session handle.
    hSession = WinHttpOpen( L"WinHTTP Example/1.0",  
                            WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
                            WINHTTP_NO_PROXY_NAME, 
                            WINHTTP_NO_PROXY_BYPASS, 0);

    // Specify an HTTP server.
    if (hSession)
        hConnect = WinHttpConnect( hSession, L"www.microsoft.com",
                                   INTERNET_DEFAULT_HTTPS_PORT, 0);

    // Create an HTTP request handle.
    if (hConnect)
        hRequest = WinHttpOpenRequest( hConnect, L"GET", NULL,
                                       NULL, WINHTTP_NO_REFERER, 
                                       WINHTTP_DEFAULT_ACCEPT_TYPES, 
                                       WINHTTP_FLAG_SECURE);

    // Send a request.
    if (hRequest)
        bResults = WinHttpSendRequest( hRequest,
                                       WINHTTP_NO_ADDITIONAL_HEADERS,
                                       0, WINHTTP_NO_REQUEST_DATA, 0, 
                                       0, 0);

 
    // End the request.
    if (bResults)
        bResults = WinHttpReceiveResponse( hRequest, NULL);

    // Keep checking for data until there is nothing left.
    if (bResults)
        do 
        {
            // Check for available data.
            dwSize = 0;
            if (!WinHttpQueryDataAvailable( hRequest, &dwSize))
                printf("Error %u in WinHttpQueryDataAvailable.\n", GetLastError());

            // Allocate space for the buffer.
            pszOutBuffer = new char[dwSize+1];
            if (!pszOutBuffer)
            {
                printf("Out of memory\n");
                dwSize=0;
            }
            else
            {
                // Read the Data.
                ZeroMemory(pszOutBuffer, dwSize+1);

                if (!WinHttpReadData( hRequest, (LPVOID)pszOutBuffer, 
                                      dwSize, &dwDownloaded))
                    printf( "Error %u in WinHttpReadData.\n", GetLastError());
                else
                    printf( "%s\n", pszOutBuffer);
            
                // Free the memory allocated to the buffer.
                delete [] pszOutBuffer;
            }

        } while (dwSize > 0);


    // Report any errors.
    if (!bResults)
        printf("Error %d has occurred.\n", GetLastError());

    // Close any open handles.
    if (hRequest) WinHttpCloseHandle(hRequest);
    if (hConnect) WinHttpCloseHandle(hConnect);
    if (hSession) WinHttpCloseHandle(hSession);

https://docs.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpconnect

 

 

 

MS 제공정보.

 

 

Windows HTTP 서비스 - Win32 apps

WinHTTP(Microsoft Windows HTTP 서비스)는 개발자에게 HTTP 프로토콜을 통해 다른 HTTP 서버로 요청을 보낼 수 있는 HTTP 클라이언트 API(애플리케이션 프로그래밍 인터페이스)를 제공합니다.

docs.microsoft.com

 

 

 

 

 

WinHTTP의 SSL - Win32 apps

WinHTTP(Microsoft Windows HTTP 서비스)는 클라이언트 인증서를 포함한 SSL(SSL(Secure Sockets Layer)) 트랜잭션을 지원합니다. 이 항목에서는 SSL 트랜잭션과 관련된 개념과 WinHTTP를 사용하여 처리하는 방법에

docs.microsoft.com

 

 

 

연관

 

 

WebSocket. 웹소켓.

개요 WebSocket - 웹서버와 브라우저간 지속연결된 TCP 기반 양방향 실시간 통신 가능한 기술 사양. - HTML5 에서 WebSocket 사양이 정의되고 있다. - 표준화된 순수 웹 환경(즉, 추가의 플러그인 프로그램

igotit.tistory.com

 

 

 

 

 


첫 등록 : 2022.01.24

최종 수정 : 2022.03.09

단축 주소 : https://igotit.tistory.com/3359


 

 

 

 

 

 

댓글



 

비트코인




암호화폐       외환/나스닥/골드       암호화폐/외환/나스닥/골드 암호화폐/외환/나스닥/골드   암호화폐/외환/나스닥/골드
     
현물 |선물 인버스 |선물 USDT       전략매니저(카피트레이딩)     롤오버 이자 없는 스왑프리계좌
( 스왑프리 암호화폐도 거래 가능 )    
MT4, MT5 , cTrader 모두 지원     FTMO 계좌 매매운용. MT4,MT5