简体   繁体   English

使用ISAPI筛选器将标头导入文件

[英]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 ÌÌÌÌÌÌÌÌÌÌÌ. 我试图将整个原始标头保存到文件中,但是每次尝试写入内容时,都会得到一个充满full的文件。 What am I doing wrong? 我究竟做错了什么?

DWORD CTryISAPIFilter::OnPreprocHeaders(CHttpFilterContext* httpContext,
    PHTTP_FILTER_PREPROC_HEADERS headerInformation)
{


    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? headerInformation->GetHeader()返回成功吗?

If so, how much is it actually writing into buffer (presumably it tells you this in a value it places in bufferSize ) 如果是这样,它实际上要写入buffer多少(大概是通过放置在bufferSize中的值告诉您的)

I suspect that GetHeader() is failing, and nothing is being written to buffer because: 我怀疑GetHeader()失败,并且没有任何内容写入buffer因为:

  • you're getting all "ÌÌÌÌÌÌÌÌÌÌÌ" characters (which is what the debug builds of VC will set uninitialized memory to), and 您将得到所有“ÌÌÌÌÌÌÌÌÌÌÌ”字符(这是VC的调试版本将未初始化的内存设置为),并且
  • 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). 当您对postData2索引时,通常不会在字符串的末尾(无论如何,无论如何),都不会引发异常。 So there's apparently no '\\0' terminator in buffer (which GetHeader() will write if it succeeds). 因此, buffer显然没有'\\ 0'终止GetHeader()如果成功, GetHeader()将写入该终止符)。

You need to check for this failure and examine GetLastError() to get more information on what the failure is. 您需要检查此故障并检查GetLastError()以获得有关故障原因的更多信息。

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. 有关如何适当调整缓冲区大小,请参见http://msdn.microsoft.com/zh-cn/magazine/cc163939.aspx

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? 更新2:自从我完成Web工作以来已经有一段时间了,但是“ ALL_RAW”不是CGI风格的服务器环境变量,而不是标题吗? Shouldn't you retrieve this using GetServerVariable() instead of GetHeader() ? 您不应该使用GetServerVariable()而不是GetHeader()来检索它吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM