Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Handle POST Requests in a Pluggable Protocol Handler


View products that this article applies to.

This article was previously published under Q280522

↑ Back to the top


Summary

It is sometimes desirable to have a pluggable protocol as the target of FORM POST requests. This article outlines how to handle POST requests in an asynchronous pluggable protocol handler (APPH).

↑ Back to the top


More information

The APPH receives the POST data (by way of URLMON) from the client as part of the BINDINFO structure, as described in the following article in the Microsoft Knowledge Base:
165800� PostMon.exe Demonstrates How to Use URL Moniker to POST Data
In addition, the MIME type of the POST data can be retrieved by means of the IInternetBindInfo::GetBindString method with a first parameter of BINDSTRING_POST_DATA_MIME.

With this background information, you can use the following code to obtain the POST data from within an APPH's IInternetProtocol::Start() method:
STDMETHODIMP CMyPlugProt::Start(
        LPCWSTR szUrl,
        IInternetProtocolSink *pIProtSink,
        IInternetBindInfo *pIBindInfo,
        DWORD grfSTI,
        DWORD dwReserved)
{

	// Retrieve POST data.
	// m_bindinfo and m_bindf are members of the CMyPlugProt class, declared as:
	// 	BINDINFO m_bindinfo;
	// 	DWORD m_bindf;

	m_bindinfo.cbSize = sizeof(BINDINFO);
	if (pIBindInfo)
		hr = pIBindInfo->GetBindInfo(&m_bindf, &m_bindinfo);
	
	switch (m_bindinfo.dwBindVerb)
	{
	case    BINDVERB_POST:
		void *pData;
		UINT cPostData;	// Post data size.
		
		if (m_bindinfo.stgmedData.tymed != TYMED_HGLOBAL)
			break;
		
		cPostData = m_bindinfo.cbstgmedData;
		if (!cPostData)
			break;
		
		pData = GlobalLock(m_bindinfo.stgmedData.hGlobal);
		if (pData)
		{
			// Allocate space to store the POST data if required.
			// For instance, a member variable, m_postData, 
			// declared as "BYTE *m_postData;", could be used 
			// as below:
			// 	m_postData = new BYTE[cPostData];
			// 	memcpy(m_postData, pData, cPostData);
			
			// After checking the data, unlock buffer.
			GlobalUnlock(m_bindinfo.stgmedData.hGlobal);
			
			// Retrieve MIME type of the post data.
			LPOLESTR pszMIMEType;	
			ULONG dwSize;
			hr = pIBindInfo->GetBindString(
				BINDSTRING_POST_DATA_MIME, &pszMIMEType, 1, &dwSize);
			
			if(hr == S_OK)
			{
				// pszMIMEType now contains the MIME type of the post data.
				// This would typically be "application/x-www-form-urlencoded" 
				// for a POST. In general, it could be any (standard or 
				// otherwise) MIME type. Many of the standard MIME type strings 
				// are #defined in <URLMon.h>. For instance, CFSTR_MIME_TEXT 
				// is L"text/plain".
				
				// Store the MIME type in a member variable here, if required.

				// Finally, free pszMIMEType via CoTaskMemFree.
				if (pszMIMEType)
				{
					CoTaskMemFree(pszMIMEType);
					pszMIMEType = NULL;
				}
			}
			else
			{
				// Assume "application/x-www-form-urlencoded".
			}
			
		}
		
		break;
		
	default:
		// It's a GET.
		break;
	}

}	// End of function STDMETHODIMP CMyPlugProt::Start()
				

↑ Back to the top


References

For additional information, see the following articles on the Microsoft Developer Network: For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

↑ Back to the top


Keywords: KB280522, kburlmon, kbhowto

↑ Back to the top

Article Info
Article ID : 280522
Revision : 4
Created on : 5/24/2007
Published on : 5/24/2007
Exists online : False
Views : 516