다음을 통해 공유


IReadEntityProvider::GetEntity 메서드

요청 엔터티를 검색합니다.

구문

virtual VOID GetEntity(  
   PVOID* ppBuffer,  
   DWORD* pcbData,  
   DWORD* pcbBuffer  
) = 0;  

매개 변수

ppBuffer
요청 엔터티를 포함하는 void 버퍼에 대한 포인터입니다.

pcbData
의 데이터 ppBuffer크기를 포함하는 에 대한 포인터 DWORD 입니다.

pcbBuffer
버퍼의 ppBuffer 크기를 포함하는 에 대한 포인터 DWORD 로, 보다 크거나 같아야 합니다pcbData.

반환 값

VOID.

설명

메서드를 GetEntity 호출한 후 매개 변수는 요청 엔터티를 지정합니다. pcbData 매개 변수는 에서 반환 ppBuffer; 된 요청 엔터티의 데이터의 크기(바이트)를 지정하고 pcbBuffer 매개 변수는 에서 가리키는 요청 엔터티 버퍼의 크기(바이트)를 ppBuffer지정 ppBuffer 합니다.

참고

pcbBuffer 는 항상 보다 크거나 같아야 합니다 pcbData.

예제

다음 코드 예제에서는 다음 작업을 수행하는 HTTP 모듈을 만드는 방법을 보여 줍니다.

  1. 메서드를 사용하여 요청 엔터티를 검색합니다 GetEntity .

  2. 요청 엔터티 데이터의 크기와 버퍼 크기를 포함하는 문자열 배열을 만듭니다.

  3. 요청 엔터티 정보가 포함된 이벤트 뷰어 로그 항목을 작성한 다음 종료합니다.

#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>

// NOTE - Data needs to be passed to this module, e.g. a POST request, or it will not appear to return anything.

// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
    REQUEST_NOTIFICATION_STATUS
    OnReadEntity(
        IN IHttpContext * pHttpContext,
        IN IReadEntityProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pHttpContext );
        
        // Create buffers for the request entity information.
        PVOID pBuffer = NULL;
        DWORD cbData = 0;
        DWORD cbBuffer = 0;
        
        // Retrieve the request entity.
        pProvider->GetEntity(&pBuffer,&cbData,&cbBuffer);
        
        // Create string buffers for the return messages.
        char szData[30];
        char szBuffer[30];

        // Format the return messages.
        sprintf_s(szData,29,"Data Size: %u",cbData);
        sprintf_s(szBuffer,29,"Buffer Size: %u",cbBuffer);
        
        // Create an array of strings for the event viewer log.
        LPCSTR szReturn[3] = {"Request Entity Information",szData,szBuffer};
        // Write the strings to the Event Viewer.
        WriteEventViewerLog(szReturn,3);

        // Return processing to the pipeline.
        return RQ_NOTIFICATION_CONTINUE;
    }

    MyHttpModule()
    {
        // Open a handle to the Event Viewer.
        m_hEventLog = RegisterEventSource( NULL,"IISADMIN" );
    }

    ~MyHttpModule()
    {
        // Test whether the handle for the Event Viewer is open.
        if (NULL != m_hEventLog)
        {
            // Close the handle to the Event Viewer.
            DeregisterEventSource( m_hEventLog );
            m_hEventLog = NULL;
        }
    }

private:

    // Create a handle for the event viewer.
    HANDLE m_hEventLog;

    // Define a method that writes to the Event Viewer.
    BOOL WriteEventViewerLog(LPCSTR szBuffer[], WORD wNumStrings)
    {
        // Test whether the handle for the Event Viewer is open.
        if (NULL != m_hEventLog)
        {
            // Write any strings to the Event Viewer and return.
            return ReportEvent(
                m_hEventLog,
                EVENTLOG_INFORMATION_TYPE,
                0, 0, NULL, wNumStrings,
                0, szBuffer, NULL );
        }
        return FALSE;
    }
};

// Create the module's class factory.
class MyHttpModuleFactory : public IHttpModuleFactory
{
public:
    HRESULT
    GetHttpModule(
        OUT CHttpModule ** ppModule, 
        IN IModuleAllocator * pAllocator
    )
    {
        UNREFERENCED_PARAMETER( pAllocator );

        // Create a new instance.
        MyHttpModule * pModule = new MyHttpModule;

        // Test for an error.
        if (!pModule)
        {
            // Return an error if the factory cannot create the instance.
            return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
        }
        else
        {
            // Return a pointer to the module.
            *ppModule = pModule;
            pModule = NULL;
            // Return a success status.
            return S_OK;
        }            
    }

    void Terminate()
    {
        // Remove the class from memory.
        delete this;
    }
};

// Create the module's exported registration function.
HRESULT
__stdcall
RegisterModule(
    DWORD dwServerVersion,
    IHttpModuleRegistrationInfo * pModuleInfo,
    IHttpServer * pGlobalInfo
)
{
    UNREFERENCED_PARAMETER( dwServerVersion );
    UNREFERENCED_PARAMETER( pGlobalInfo );

    // Set the request notifications and exit.
    return pModuleInfo->SetRequestNotifications(
        new MyHttpModuleFactory,
        RQ_READ_ENTITY,
        0
    );
}

모듈은 RegisterModule 함수를 내보내야 합니다. 프로젝트에 대한 모듈 정의(.def) 파일을 만들어 이 함수를 내보내거나 스위치를 사용하여 /EXPORT:RegisterModule 모듈을 컴파일할 수 있습니다. 자세한 내용은 연습: 네이티브 코드를 사용하여 Request-Level HTTP 모듈 만들기를 참조하세요.

필요에 따라 각 함수에 대한 호출 규칙을 명시적으로 선언하는 대신 호출 규칙을 사용하여 __stdcall (/Gz) 코드를 컴파일할 수 있습니다.

요구 사항

형식 Description
클라이언트 - Windows Vista의 IIS 7.0
- Windows 7의 IIS 7.5
- Windows 8의 IIS 8.0
- WINDOWS 10 IIS 10.0
서버 - Windows Server 2008의 IIS 7.0
- Windows Server 2008 R2의 IIS 7.5
- Windows Server 2012의 IIS 8.0
- Windows Server 2012 R2의 IIS 8.5
- WINDOWS SERVER 2016 IIS 10.0
제품 - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0
- IIS Express 7.5, IIS Express 8.0, IIS Express 10.0
헤더 Httpserv.h

참고 항목

IReadEntityProvider 인터페이스
IReadEntityProvider::SetEntity 메서드
IHttpRequest::ReadEntityBody 메서드
IHttpRequest::InsertEntityBody 메서드