CHttpFile problem accessing HTTPS from ATL
From: Nedelcho Stanev (decho_at_atlanticsky.com)
Date: 03/04/04
- Next message: Crosbie Fitch: "Re: Style advice on strange but valid usage"
- Previous message: Crosbie Fitch: "How to detect server invoked by COM as opposed to user?"
- Messages sorted by: [ date ] [ thread ]
Date: 4 Mar 2004 10:18:24 -0800
Hello All,
I have COM component - sink for exchange.
And i want to access from this component some secure web site
to post data.
And i tried with CHttpFile from MFC , used from me
in lot of projects.
What was my surprise when i understand that this simply doesent
works.
Or no, it works, but, with very strange behavior.
When i set flags to ignore wrong CA certificates - it doesent work
simply
and i get error:
"The certificate authority is invalid or incorrect"
This is confusing for me because same code in standalone exe works
very fine.
Then i extract this code and put in separated dll.
Result is same, from standalone exe , linked with this dll it works
perfect, from COM object - never.
So , for me is curious what is this strange behavior, is it known bug
?
or problems are in mine code?
and second strange problem is that , ok i disable security and try to
access normal web site on port 80. Then i see in logs of server that
whatever i put as method it issue "GET" to the server and never "POST"
Can someone help with resolving of this?
Below is code for function which i use in dll:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
extern "C" DWORD PASCAL EXPORT GetWebFile2(std::string& pMem, CString
strData, bool bSecure)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
DWORD dwFlags = 0;
int icntread = 0;
int numread = 0;
CHttpFile* file = NULL;
CHttpConnection* server = NULL;
TCHAR szErr[COMMON_BUFSIZE];
szErr[0] = '\0';
DWORD dwSessionFlags;
if( bSecure )
dwSessionFlags = INTERNET_FLAG_EXISTING_CONNECT
| INTERNET_FLAG_NO_AUTO_REDIRECT |
INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE |
INTERNET_FLAG_SECURE | INTERNET_FLAG_IGNORE_CERT_DATE_INVALID |
INTERNET_FLAG_IGNORE_CERT_CN_INVALID ;
else
dwSessionFlags = INTERNET_FLAG_EXISTING_CONNECT
| INTERNET_FLAG_NO_AUTO_REDIRECT |
INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE ;
CInternetSession session(HTTPS_SESSION_NAME);
try {
if( bSecure )
server=session.GetHttpConnection(HTTPS_LOCALHOST,HTTPS_PORT,MQUBE_RPCUSER,MQUBE_RPCPASSWORD);
else
server=session.GetHttpConnection(HTTPS_LOCALHOST,HTTP_PORT,MQUBE_RPCUSER,MQUBE_RPCPASSWORD);
file=server->OpenRequest(
CHttpConnection::HTTP_VERB_POST,
HTTPS_REQ_BASE,
NULL,
1,
NULL,
NULL,
dwSessionFlags );
} catch (CInternetException* pEx) {
if(!pEx->GetErrorMessage(szErr, COMMON_BUFSIZE))
strcpy(szErr,"Unknown error.");
LogLineToLogServer(MQ_LOG_DEBUG,"[80500] Cannot initialize
session:%s.\n",szErr);
file=NULL;
pEx->Delete();
return -1;
}
if (server==NULL)
return -2;
if (file!=NULL) {
if( bSecure ) {
// disable CA check
file->QueryOption( INTERNET_OPTION_SECURITY_FLAGS, dwFlags );
dwFlags |= SECURITY_FLAG_IGNORE_UNKNOWN_CA;
file->SetOption( INTERNET_OPTION_SECURITY_FLAGS, dwFlags );
}
// send header
file->AddRequestHeaders(HTTPS_HEADER);
try {
// finaly - send request
file->SendRequest(NULL,0,(void
*)(LPCTSTR)strData,strData.GetLength());
} catch (CInternetException* pEx) {
if(!pEx->GetErrorMessage(szErr, COMMON_BUFSIZE))
strcpy(szErr,"Some crazy unknown error");
LogLineToLogServer(MQ_LOG_DEBUG,"[80501] Cannot send
request:%s.\n",szErr);
file=NULL;
server->Close();
delete server;
pEx->Delete();
return -3;
}
// and process response
while ((icntread = file->Read(szErr,COMMON_BUFSIZE)) > 0)
{
numread += icntread;
pMem.append(szErr,icntread);
memset(szErr,0x00,COMMON_BUFSIZE);
}
file->Close();
delete file;
}
server->Close();
delete server;
return numread;
}
- Next message: Crosbie Fitch: "Re: Style advice on strange but valid usage"
- Previous message: Crosbie Fitch: "How to detect server invoked by COM as opposed to user?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|