能夠嘗試經過 HttpAddRequestHeaders 來添加自已的COOKIE:web
char * lpszHeaders = "Cookie: Key=somevalue";
DWORD dwHeadersLength = strlen(lpszHeaders);
HttpAddRequestHeaders(hOpenRequest, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD);dom
函數會返回成功,但實際上COOKIE可能並無添加上去,建議在調用HttpOpenRequest時指定 INTERNET_FLAG_NO_COOKIES選項。然而這個選項將阻止WinInet內部添加所需的COOKIE,所以你要負責全部必需的 COOKIE。另外一個函數InternetSetCookie也能夠設置COOKIE,但我從未用過。ide
若是須要檢查返回的COOKIE,能夠嘗試使用HttpQueryInfo,並將其中的dwInfoLevel設置爲HTTP_QUERY_SET_COOKIE。函數
下面是MFC代碼例子:spa
try
{
CInternetSession Session ;
CHttpConnection *pHttpConnect = Session.GetHttpConnection( "www.abc.net" ) ;
if( pHttpConnect )
{
CHttpFile* pFile = pHttpConnect->OpenRequest( CHttpConnection::HTTP_VERB_GET,
_T("/memberexists.srf?x="),
NULL,
1,
NULL,
NULL,