Freigeben über


IHttpRequest::GetRawHttpRequest-Methode

Gibt eine Struktur zurück, die die unformatierte HTTP-Anforderung enthält.

Syntax

virtual HTTP_REQUEST* GetRawHttpRequest(  
   VOID  
) = 0;  

Parameter

Diese Methode nimmt zwei Parameter entgegen.

Rückgabewert

Ein Zeiger auf eine HTTP_REQUEST-Struktur .

Bemerkungen

Die GetRawHttpRequest -Methode ruft die Rohanforderung ab und gibt einen Zeiger auf eine HTTP_REQUEST Struktur zurück, die die aktuelle Anforderungsentität enthält.

Hinweis

Die HTTP_REQUEST Struktur wird in der Datei Http.h definiert.

Die Lebensdauer dieser Struktur wird vom Server gesteuert, und die Struktur ist bis zum Ende der Anforderung verfügbar.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie Sie mithilfe der GetRawHttpRequest -Methode ein HTTP-Modul erstellen, das die HTTP_REQUEST Struktur für die aktuelle Anforderung abruft. Das Codebeispiel zeigt dann, wie Sie die Struktur verwenden, um das HTTP-Verb, die HTTP-Hauptversion und die HTTP-Nebenversion für die Anforderung abzurufen.

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

// Create the module class.
class MyHttpModule : public CHttpModule
{
public:
    REQUEST_NOTIFICATION_STATUS
    OnBeginRequest(
        IN IHttpContext * pHttpContext,
        IN IHttpEventProvider * pProvider
    )
    {
        UNREFERENCED_PARAMETER( pProvider );

        // Retrieve a pointer to the request.
        IHttpRequest * pHttpRequest = pHttpContext->GetRequest();

        // Test for an error.
        if (pHttpRequest != NULL)
        {
            // Return the raw HTTP_REQUEST structure. (Defined in the Http.h file.)
            HTTP_REQUEST * pRawRequest = pHttpRequest->GetRawHttpRequest();
            // Test for an error.
            if (pRawRequest != NULL)
            {
                // Retrieve the ID of the HTTP verb.
                // (From the HTTP_VERB enumeration defined in the Http.h file.)
                long HttpVerb = pRawRequest->Verb;
                // Retrieve the HTTP version.
                // (From the HTTP_VERSION structure defined in the Http.h file.)
                USHORT HttpMajorVersion = pRawRequest->Version.MajorVersion;
                USHORT HttpMinorVersion = pRawRequest->Version.MinorVersion;
            }
        }

        // 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_BEGIN_REQUEST,
        0
    );
}


Ihr Modul muss die Funktion RegisterModule exportieren. Sie können diese Funktion exportieren, indem Sie eine Moduldefinitionsdatei (.def) für Ihr Projekt erstellen, oder Sie können das Modul mithilfe des /EXPORT:RegisterModule Switches kompilieren. Weitere Informationen finden Sie unter Exemplarische Vorgehensweise: Erstellen eines Request-Level HTTP-Moduls mithilfe von nativem Code.

Sie können den Code optional kompilieren, indem Sie die __stdcall (/Gz) aufrufende Konvention verwenden, anstatt die aufrufende Konvention für jede Funktion explizit zu deklarieren.

Anforderungen

type BESCHREIBUNG
Client – IIS 7.0 unter Windows Vista
– IIS 7.5 unter Windows 7
– IIS 8.0 unter Windows 8
– IIS 10.0 auf Windows 10
Server – IIS 7.0 unter Windows Server 2008
– IIS 7.5 unter Windows Server 2008 R2
– IIS 8.0 unter Windows Server 2012
– IIS 8.5 unter Windows Server 2012 R2
– IIS 10.0 auf Windows Server 2016
Produkt – 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

Weitere Informationen

IHttpRequest-Schnittstelle
IHttpResponse::GetRawHttpResponse-Methode