Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Menentukan entitas permintaan.
Sintaks
virtual VOID SetEntity(
PVOID pBuffer,
DWORD cbData,
DWORD cbBuffer
) = 0;
Parameter
pBuffer
Penunjuk ke buffer kekosongan yang berisi entitas permintaan.
cbData
DWORD yang berisi ukuran data dalam pBuffer.
cbBuffer
DWORD yang berisi ukuran pBuffer buffer, yang harus lebih besar dari atau sama dengan cbData.
Tampilkan Nilai
VOID.
Keterangan
Metode ini SetEntity menggantikan isi entitas permintaan HTTP yang telah dimuat sebelumnya dengan badan entitas yang diacu oleh pBuffer parameter . Parameter cbData harus menentukan ukuran, dalam byte, data dalam entitas permintaan yang dikembalikan dalam pBuffer, dan cbBuffer parameter harus menentukan ukuran, dalam byte, dari buffer entitas permintaan yang diacu oleh pBuffer.
Catatan
cbBuffer harus selalu lebih besar dari atau sama dengan cbData.
Contoh
Contoh kode berikut menunjukkan cara membuat modul HTTP yang melakukan tugas berikut:
Mengalokasikan buffer 1 KB. Jika buffer tidak dapat dialokasikan, modul mengembalikan kesalahan dan keluar.
Membuat string yang berisi nilai respons.
Menentukan entitas permintaan dengan menggunakan
SetEntitymetode , lalu keluar.
#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
);
}
Modul Anda harus mengekspor fungsi RegisterModule . Anda dapat mengekspor fungsi ini dengan membuat file definisi modul (.def) untuk proyek Anda, atau Anda dapat mengkompilasi modul dengan menggunakan sakelar /EXPORT:RegisterModule . Untuk informasi selengkapnya, lihat Panduan: Membuat Modul HTTP Request-Level Dengan Menggunakan Kode Asli.
Anda dapat secara opsional mengkompilasi kode dengan menggunakan __stdcall (/Gz) konvensi panggilan alih-alih secara eksplisit mendeklarasikan konvensi panggilan untuk setiap fungsi.
Persyaratan
| Jenis | Deskripsi |
|---|---|
| Klien | - IIS 7.0 di Windows Vista - IIS 7.5 di Windows 7 - IIS 8.0 di Windows 8 - IIS 10.0 pada Windows 10 |
| Server | - IIS 7.0 di Windows Server 2008 - IIS 7.5 di Windows Server 2008 R2 - IIS 8.0 di Windows Server 2012 - IIS 8.5 di Windows Server 2012 R2 - IIS 10.0 di Windows Server 2016 |
| Produk | - 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 |
| Header | Httpserv.h |
Lihat juga
Antarmuka IReadEntityProvider
IReadEntityProvider::Metode GetEntity
Metode IHttpRequest::ReadEntityBody
Metode IHttpRequest::InsertEntityBody