VC++ ATL编写的控件在执行HTTP上传时奇数次成功,偶数次失败,主代码如下:    {
        m_httpSession    = ::InternetOpen(httpSession_Agent_name,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
        _variant_t vttSvrName;
        vttSvrName    = pwszSvrName;
        TCHAR *svrName;
        svrName= _com_util::ConvertBSTRToString(vttSvrName.bstrVal);
        // 连接服务器
        HINTERNET hConnect = InternetConnect(m_httpSession, 
            svrName, 
            INTERNET_DEFAULT_HTTP_PORT, 
            NULL, 
            NULL, 
            INTERNET_SERVICE_HTTP, 
            0, 
            1);
        if (!hConnect) return E_UNEXPECTED;
        LPWSTR pwszHDSTemp    = L"Content-Type: application/x-www-form-urlencoded\nAccept: */*\nAccept-Encoding: gzip, deflate\nAccept-Language: zh-cn\nCookie: ASP.NET_SessionId=";
        LPWSTR pwszHDS        = NULL;
        pwszHDS    = DsoCopyStringCat(pwszHDSTemp,pwszSessionID);
        LPWSTR pwszFullTargetUrl    = NULL;
        pwszFullTargetUrl    = DsoCopyString(pwszTargetUrl);
        pwszFullTargetUrl    = DsoCopyStringCat(pwszFullTargetUrl,L"?");
        pwszFullTargetUrl    = DsoCopyStringCat(pwszFullTargetUrl,pwszUrlHead);
        _variant_t vttTargetUrl, vttHDS;
        vttTargetUrl    = pwszFullTargetUrl;
        vttHDS            = pwszHDS;        TCHAR *buf;
        TCHAR *hdrs;
        buf    = _com_util::ConvertBSTRToString(vttTargetUrl.bstrVal);
        hdrs= _com_util::ConvertBSTRToString(vttHDS.bstrVal);
        static TCHAR accept[] = _T("Accept: */*");        HINTERNET hRequest = HttpOpenRequest(hConnect,
            "POST",
            buf,
            HTTP_VERSION,
            NULL, 
            NULL,
            0, 
            1);
        if (!hRequest) return E_UNEXPECTED;
        HttpAddRequestHeaders(hRequest,hdrs,lstrlen(hdrs),HTTP_ADDREQ_FLAG_ADD);
        INTERNET_BUFFERS BufferIn;
        DWORD dwBytesWritten;
        BYTE pBuffer[1024];
        BOOL bRet, bRead;        BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS ); // Must be set or error will occur
        BufferIn.Next = NULL; 
        BufferIn.lpcszHeader = NULL;
        BufferIn.dwHeadersLength = 0;
        BufferIn.dwHeadersTotal = 0;
        BufferIn.lpvBuffer = NULL;                
        BufferIn.dwBufferLength = 0;
        BufferIn.dwOffsetLow = 0;
        BufferIn.dwOffsetHigh = 0;
        DWORD dwPostSize = ::GetFileSize(hFile,NULL);
        BufferIn.dwBufferTotal = dwPostSize; // This is the only member used other than dwStructSize        if(!(hr=HttpSendRequestEx( hRequest, &BufferIn, NULL, 0, 0)))
        {
            return hr;
        }
        while (SUCCEEDED(hr))
        {
            if (FALSE == ReadFile(hFile, pBuffer, 1024, &cbRead, NULL))
            {
                hr = E_WIN32_LASTERROR;
                break;
            }
            if (0 == cbRead) break;
            if (!(bRet=InternetWriteFile( hRequest, pBuffer, 1024, &dwBytesWritten))){
                hr    = E_UNEXPECTED;
                break;
            }
        }
        CloseHandle(hFile);
        MessageBox(m_hwnd, 
            "即将关闭Request",
            "调试", MB_ICONINFORMATION|MB_SETFOREGROUND);
        if(!HttpEndRequest(hRequest, NULL, 0, 0)){
            return E_UNEXPECTED;
        }
        MessageBox(m_hwnd, 
            "关闭Request成功",
            "调试", MB_ICONINFORMATION|MB_SETFOREGROUND);
        char pcBuffer[BUFFSIZE];        DWORD dwBytesRead;
        {
            dwBytesRead=0;
            bRead    = InternetReadFile(hRequest, pcBuffer, BUFFSIZE-1, &dwBytesRead);
            if (bRead){
                MessageBox(m_hwnd, 
                    pcBuffer,
                    "文件上传结果", MB_ICONINFORMATION|MB_SETFOREGROUND);
            }
        }
        // 清除句柄
        if (hRequest)
           InternetCloseHandle(hRequest);
        if (hConnect)
           InternetCloseHandle(hConnect);
        //if (m_httpSession)
        //   InternetCloseHandle(m_httpSession);
    }
返回信息:(没有异常发生,但返回的东西不对,并且在Web应用程序一端没跟踪到数据提交)
<html><head><title>Error</title></head><body>The parameter is incorrect. </body></html>测试范围:ActiveX Control Test Container和IE嵌入都有这个问题。在用IE进行测试时,当我上传成功后,按Ctrl+N新开窗口,打开的页面的源代码就是:
<html><head><title>Error</title></head><body>The parameter is incorrect. </body></html>但如果我上传失败后,按Ctrl+N新开窗口,打开的页面则是正常的。
百思不得其解,就好象是偶数次调用时不知道发到什么地方去了。各位大侠有什么好建议?