VC完成表单提交并设置获取COOKIE:

能够测验经过 HttpAddRequestHeaders 来增加自已的COOKIE:     char * lpszHeaders = "Cookie: Key=somevalue";     DWORD dwHeadersLength = strlen(lpszHeaders);     HttpAddRequestHeaders(hOpenRequest, lpszHeaders, dwHeahttp://www.fpzhuhai.com/linked/20130306.do,dersLength,           HTTP_ADDREQ_FLAG_ADD);      函数会回来成功,但实际上COOKIE能够并没有增加上去,主张在调用HttpOpenRequest时指定 INTERNET_FLAG_NO_COOKIES选项。但是这个选项将阻碍WinInet内部增加所需的COOKIE,因而你要担任一切必需的 COOKIE。另一个函数InternetSetCookie也能够设置COOKIE,但我从未用过。     若是需求查看回来的COOKIE,能够测验运用HttpQueryInfo,并将其间的dwInfoLevel设置为HTTP_QUERY_SET_COOKIE。     该计划的可行的,由于cookies实际上就是头的一部分,只需紧贴头的尾部,就没有任何问题。          下面是MFC代码比如: 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,                  INTERNET_FLAG_NO_COOKIES ); //     if ( pFile )     {         pFile->AddRequestHeaders("Accept: image/png,*/*;q=0.5");      pFile->AddRequestHeaders("Accept-Language: zh-cn,zh;q=0.5");      pFile->AddRequestHeaders("Accept-Encoding: gzip,deflate");      pFile->AddRequestHeaders("Accept-Charset: gb2312,utf-8;q=0.7,*;q=0.7");      pFile->AddRequestHeaders("Keep-Alive: 300");      pFile->AddRequestHeaders("Connection: keep-alive");      pFile->AddRequestHeaders("Cookie: Key=somevalue;domain=abc.com") ;           pFile->SendRequest();           // 回来的HTML      //CString s ;      //while (pFile->ReadString(s))      //str  = s ;      // 取回来的COOKIE      CString strInfo ;      DWORD dw = 0 ;      pFile->QueryInfo(HTTP_QUERY_SET_COOKIE ,strInfo ,http://www.haofapiao.com/linked/20130306.do
posted @ 2013-03-07 02:32  chinadiy197601  阅读(400)  评论(0编辑  收藏  举报