다음을 통해 공유


IReadEntityProvider::SetEntity 메서드

요청 엔터티를 지정합니다.

구문

virtual VOID SetEntity(  
   PVOID pBuffer,  
   DWORD cbData,  
   DWORD cbBuffer  
) = 0;  

매개 변수

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

cbData
DWORD 의 데이터 크기를 포함하는 입니다pBuffer.

cbBuffer
DWORD 버퍼의 pBuffer 크기를 포함하는 입니다. 이 크기는 보다 크거나 같아야 합니다cbData.

반환 값

VOID.

설명

메서드는 SetEntity 미리 로드된 HTTP 요청 엔터티 본문을 매개 변수가 가리키는 엔터티 본문으로 pBuffer 바꿉니다. 매개 변수는 cbData 에서 반환 pBuffer된 요청 엔터티의 데이터의 크기(바이트)를 지정해야 하며 cbBuffer 매개 변수는 에서 가리키는 요청 엔터티 버퍼의 크기(바이트)를 pBuffer지정해야 합니다.

참고

cbBuffer 는 항상 보다 크거나 같아야 합니다 cbData.

예제

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

  1. 1KB 버퍼를 할당합니다. 버퍼를 할당할 수 없는 경우 모듈은 오류를 반환하고 종료합니다.

  2. 응답 값이 포함된 문자열을 만듭니다.

  3. 메서드를 사용하여 요청 엔터티를 SetEntity 지정한 다음 종료합니다.

#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
    )
    {
        // Allocate a 1K buffer for the request entity.
        DWORD cbBuffer = 1024;
        void * pvBuffer = pHttpContext->AllocateRequestMemory(cbBuffer);
        
        // Test for an error.
        if (NULL == pvBuffer)
        {
            // Set the error status.
            pProvider->SetErrorStatus(
                HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY));
            // End additional processing.
            return RQ_NOTIFICATION_FINISH_REQUEST;
        }

        // Create a string to return.
        char szBuffer[] = "Name=Value";
        // Specify the exact data length.
        DWORD cbData = (DWORD) strlen(szBuffer);        
        // Copy a string into the request entity buffer.
        strcpy_s((char*)pvBuffer,cbBuffer,szBuffer);
        // Set the request entity to the buffer.
        pProvider->SetEntity(pvBuffer,cbData,cbBuffer);

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

// 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::GetEntity 메서드
IHttpRequest::ReadEntityBody 메서드
IHttpRequest::InsertEntityBody 메서드