IReadEntityProvider::SetEntity (Método)
Especifica la entidad de solicitud.
Sintaxis
virtual VOID SetEntity(
PVOID pBuffer,
DWORD cbData,
DWORD cbBuffer
) = 0;
Parámetros
pBuffer
Puntero a un búfer void que contiene la entidad de solicitud.
cbData
que DWORD
contiene el tamaño de los datos en pBuffer
.
cbBuffer
que DWORD
contiene el tamaño del pBuffer
búfer, que debe ser mayor o igual que cbData
.
Valor devuelto
VOID
.
Comentarios
El SetEntity
método reemplaza el cuerpo de la entidad de solicitud HTTP precargada por el cuerpo de la entidad al que apunta el pBuffer
parámetro . El cbData
parámetro debe especificar el tamaño, en bytes, de los datos de la entidad de solicitud que se devolvió en pBuffer
y el cbBuffer
parámetro debe especificar el tamaño, en bytes, del búfer de entidad de solicitud al pBuffer
que apunta .
Nota
cbBuffer
siempre debe ser mayor o igual que cbData
.
Ejemplo
En el ejemplo de código siguiente se muestra cómo crear un módulo HTTP que realice las siguientes tareas:
Asigna un búfer de 1 KB. Si no se puede asignar el búfer, el módulo devuelve un error y se cierra.
Crea una cadena que contiene un valor de respuesta.
Especifica la entidad de solicitud mediante el
SetEntity
método y, a continuación, sale.
#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
);
}
El módulo debe exportar la función RegisterModule . Puede exportar esta función mediante la creación de un archivo de definición de módulo (.def) para el proyecto, o bien puede compilar el módulo mediante el /EXPORT:RegisterModule
modificador . Para obtener más información, vea Tutorial: Creación de un módulo HTTP de Request-Level mediante código nativo.
Opcionalmente, puede compilar el código mediante la __stdcall (/Gz)
convención de llamada en lugar de declarar explícitamente la convención de llamada para cada función.
Requisitos
Tipo | Descripción |
---|---|
Remoto | - IIS 7.0 en Windows Vista - IIS 7.5 en Windows 7 - IIS 8.0 en Windows 8 - IIS 10.0 en Windows 10 |
Servidor | - IIS 7.0 en Windows Server 2008 - IIS 7.5 en Windows Server 2008 R2 - IIS 8.0 en Windows Server 2012 - IIS 8.5 en Windows Server 2012 R2 - IIS 10.0 en Windows Server 2016 |
Producto | - 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 |
Encabezado | Httpserv.h |
Consulte también
IReadEntityProvider (Interfaz)
IReadEntityProvider::GetEntity (Método)
IHttpRequest::ReadEntityBody (Método)
IHttpRequest::InsertEntityBody (Método)