Article ID: 165800
Article Last Modified on 8/9/2004
119591 How to Obtain Microsoft Support Files from Online Services
STDMETHODIMP
CBindStatusCallback::GetBindInfo(DWORD* pgrfBINDF,
BINDINFO* pbindInfo)
{
if (m_fRedirect && BINDVERB_POST == m_dwAction)
{
// You are being redirected by the server.
// The method is changed to GET here so no data is posted below
SetStatusText(_T("Switching method to GET"));
m_dwAction = BINDVERB_GET;
}
pgrfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE
| BINDF_PULLDATA;
pgrfBINDF |= BINDF_GETNEWESTVERSION
| BINDF_NOWRITECACHE;
// Set up the BINDINFO data structure
pbindInfo->cbSize = sizeof(BINDINFO);
pbindInfo->dwBindVerb = m_dwAction; // here's where the action is
pbindInfo->szExtraInfo = NULL;
// Initialize the STGMEDIUM.
memset(&pbindInfo->stgmedData, 0, sizeof(STGMEDIUM));
pbindInfo->grfBindInfoF = 0;
pbindInfo->szCustomVerb = NULL;
// set up action-specific members
switch(m_dwAction)
{
case BINDVERB_POST:
// only POST data when the method is POST
if (m_hDataToPost)
{
// Fill the STGMEDIUM with the data to post
// this is the only medium urlmon supports right now
pbindInfo->stgmedData.tymed = TYMED_HGLOBAL;
pbindInfo->stgmedData.hGlobal = m_hDataToPost;
pbindInfo->stgmedData.pUnkForRelease =
(LPUNKNOWN)(LPBINDSTATUSCALLBACK)this; // maintain control
AddRef(); // It will be freed on final release
// the following must be exact! GlobalSize() rounds up.
pbindInfo->cbstgmedData = m_cbDataToPost;
}
break;
case BINDVERB_GET:
break;
default:
return E_FAIL;
}
When automatically redirecting a POST request after receiving a 301 status code, some existing HTTP/1.0 user agents will erroneously change it into a GET request.
STDMETHODIMP
CBindStatusCallback::BeginningTransaction(LPCWSTR szURL,
LPCWSTR szHeaders,
DWORD dwReserved,
LPWSTR __RPC_FAR *pszAdditionalHeaders)
{
// Here's our opportunity to add headers
if (!pszAdditionalHeaders)
{
return E_POINTER;
}
*pszAdditionalHeaders = NULL;
// This header is required when performing a POST operation
if (BINDVERB_POST == m_dwAction && m_hDataToPost)
{
const WCHAR c_wszHeaders[] =
L"Content-Type: application/x-www-form-urlencoded\r\n";
LPWSTR wszAdditionalHeaders =
(LPWSTR)CoTaskMemAlloc(
(wcslen(c_wszHeaders)+1) *sizeof(WCHAR));
if (!wszAdditionalHeaders)
{
return E_OUTOFMEMORY;
}
wcscpy(wszAdditionalHeaders, c_wszHeaders);
*pszAdditionalHeaders = wszAdditionalHeaders;
}
return NOERROR;
}
STDMETHODIMP CBindStatusCallback::OnResponse(DWORD dwResponseCode,
LPCWSTR szResponseHeaders,
LPCWSTR szRequestHeaders,
LPWSTR __RPC_FAR *pszAdditionalRequestHeaders)
{
if (!pszAdditionalRequestHeaders)
{
return E_POINTER;
}
*pszAdditionalRequestHeaders = NULL;
return NOERROR;
}
Additional query words: PostMon
Keywords: kbinfo kbdownload kbfile kbsample KB165800