• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1188
  • Last Modified:

How to retrieve https webpage using visual c++

Dear pro,

For example: https://www.mywebsite.com/userinfo.php?uid=342&type=3SS

how do I retrieve above webpage directly, and through a proxy server?

Thanks
0
njmoneer
Asked:
njmoneer
  • 3
1 Solution
 
Raj_KauCommented:
use AfxParseURL for parse url and use AFX_INET_SERVICE_HTTPS
like this

if page take Get request;

void GetMyPage()
{
DWORD   dwAccessType = INTERNET_OPEN_TYPE_DIRECT;  // We are connecting to internet directly
DWORD dwServiceType;
CInternetSession session(("IP"),0, dwAccessType);
CHttpConnection* pServer = NULL;
CHttpFile* pFile = NULL;
CString strServerName ;
CString strObject;
INTERNET_PORT nPort;

AfxParseURL("https://www.mywebsite.com/userinfo.php?uid=342&type=3SS", dwServiceType, strServerName, strObject, nPort) ||      dwServiceType != AFX_INET_SERVICE_HTTPS)
pServer = session.GetHttpConnection(strServerName, nPort);
pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,strObject, NULL, 1, NULL, NULL, INTERNET_FLAG_SECURE);

pFile->SendRequest ();

//then you can write the data in a file

fp=fopen(tempfilename,"w");   //open the file to write the page content in a temp file
if(fp != NULL)
{
while(retval = (pFile->Read(buf,sizeof(buf))))
                  {
                        fwrite(buf,1,retval,fp);
                  }
                  fclose(fp);
}
pFile->Close();

}
0
 
Raj_KauCommented:
please also declare

int retval = 0;                        // Number of bytes read from the internet
char buf[1024];                        // Read the page content in buffer
FILE * fp = NULL;                  // To write the page content in a file


and also close

pServer->Close();

if (pFile != NULL)
    delete pFile;
if (pServer != NULL)
   delete pServer;
session.Close();

after pFile->Close();

tempfilename is file name in which you want to write reading data

 
0
 
Raj_KauCommented:
Now same for PROXY only change is

>> DWORD   dwAccessType = INTERNET_OPEN_TYPE_DIRECT;  // We are connecting to internet directly

now you use
DWORD   dwAccessType = INTERNET_OPEN_TYPE_PROXY;
and
>> CInternetSession session(("IP"),0, dwAccessType);

you use

session=new CInternetSession(("IP"),0, dwAccessType ,strProxyServer);

//strProxyServer is use for proxy ip

and all other things are same

i think this solve your problem
but if your request is not GET type or it is POST type then tell i also tell that also

RAJ

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now