开发者

Getting Header into file using ISAPI Filter

I am trying to get the entire raw header into a file but everytime I attempt to write the contents I get a file full of ÌÌÌÌÌÌÌÌÌÌÌ. What am I doing wrong?

DWORD CTryISAPIFilter::OnPreprocHeaders(CHttpFilterContext* httpContext,
    PHTTP_FILTER_PREPROC_HEADERS head开发者_JS百科erInformation)
{


    char buffer[4096];
    DWORD bufferSize = sizeof(buffer);

    BOOL HeaderBoolean = headerInformation->GetHeader(httpContext->m_pFC, "ALL_RAW", buffer, &bufferSize); 
    char * ptrIn = (char *) buffer;
    std::string postData2 = ptrIn;
    char * outputString = new char[4096];

    int i = 0;
    for(i=0;i<4096;i++){
        outputString[i] = postData2[i];
    }
    outputString[i+1] = NULL;


    std::ofstream outfile ("D:\\WebSites\\wwwroot\\test.txt",std::ios::app);

    outfile << outputString << std::endl;

    outfile.close(); 
    return SF_STATUS_REQ_NEXT_NOTIFICATION;
}


Is headerInformation->GetHeader() returning success?

If so, how much is it actually writing into buffer (presumably it tells you this in a value it places in bufferSize)

I suspect that GetHeader() is failing, and nothing is being written to buffer because:

  • you're getting all "ÌÌÌÌÌÌÌÌÌÌÌ" characters (which is what the debug builds of VC will set uninitialized memory to), and
  • you're not getting an exception thrown when you index postData2 well past what should usually be the end of the string (in most cases anyway). So there's apparently no '\0' terminator in buffer (which GetHeader() will write if it succeeds).

You need to check for this failure and examine GetLastError() to get more information on what the failure is.

Update: Your buffer might not be large enough. See http://msdn.microsoft.com/en-us/magazine/cc163939.aspx for how to appropriately size the buffer.

Update 2: It's been a while since I've done web stuff, but isn't "ALL_RAW" a CGI-style server environment variable rather than a header? Shouldn't you retrieve this using GetServerVariable() instead of GetHeader()?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜