Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get data from a password protected webpage

Status
Not open for further replies.

NorbertBehrens

Programmer
May 14, 2003
2
DE
Hi,

I try to get data from a password protected webpage and need a little help.

At first I want to describe the situation in the browser.

When I call the webpage, I got a page with a little login screen. This
is realized by some javascript code. I fill in the username and
password, click on 'login' and voila, there are my wanted data.
I looked at the javascript code an noticed the names of the fields. I
tried to call the webpage directly with:


... and it works fine.

Now I had to do the same in my MFC-Projekt but I failed. I was
unsuccessful with the following two attempts

#################
## First Attempt
#################
********************************************************************************************************
...
Code:
CInternetsession InternetSession(_T("AppName"),1, INTERNET_OPEN_TYPE_PRECONFIG);  
char Url = &quot;<address>?<NameOfUserField>=<username>&<NameOfPasswordField>=<password>&action=<actionname>&quot;;
CString       strServerName;  // Server
CString       strObject;      // directory
INTERNET_PORT nPort;          // port
DWORD         dwServiceType;  // accesstype
AfxParseURL(Url, dwServiceType, strServerName, strObject, nPort)
DWORD dwHttpRequestFlags = INTERNET_FLAG_RELOAD;
CHttpFile *pHttpFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET,// or HTTP_VERB_POST
                                                    strObject, NULL, 1, NULL, NULL, 
                                                    dwHttpRequestFlags);
pHttpFile->SendRequest();
CString sz;
while (pHttpFile->ReadString(sz)){
 ... 
}
********************************************************************************************************
#################
## Second Attempt
#################
...
Code:
CInternetsession InternetSession(_T(&quot;AppName&quot;),1, INTERNET_OPEN_TYPE_PRECONFIG);  
char Url = &quot;<Only_Address_without_parameter>&quot;;
CString       strServerName;  // Server
CString       strObject;      // directory
INTERNET_PORT nPort;          // port
DWORD         dwServiceType;  // accesstype
AfxParseURL(Url, dwServiceType, strServerName, strObject, nPort)
DWORD dwHttpRequestFlags = INTERNET_FLAG_RELOAD;
CHttpFile *pHttpFile = pHttpConnection->OpenRequest(CHttpConnection::HTTP_VERB_GET,// or HTTP_VERB_POST
                                                    strObject, NULL, 1, NULL, NULL, 
                                                    dwHttpRequestFlags);
CString szHeader = _T(&quot;<NameOfUserField>=<username>&<NameOfPasswordField>=<password>&action=<actionname>&quot;); 
pHttpFile->AddRequestHeaders(szHeader);
pHttpFile->SendRequest();

CString sz;
while (pHttpFile->ReadString(sz)){
 ... 
}
********************************************************************************************************

Any Idea's?
ciao
           Norbert
 
>> char Url = &quot;<address>?<NameOfUserField...

Is 'char' really the correct type there?

I have no idea what that does, but surely it's not good.

I REALLY hope that helps.
Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top