Solved

CInternetSession : undeclared identifier

Posted on 2004-10-29
1,276 Views
Last Modified: 2008-01-09
With the code below, i always get: error C2065: 'CInternetSession' : undeclared identifier
Why?

CInternetSession session;
CHttpFile *httpFile = session->OpenURL("MonUrl/Mypage");
httpFile->Close();
0
Question by:mammouth
    9 Comments
     
    LVL 86

    Expert Comment

    by:jkr
    You need to

    #include <afxinet.h>
    0
     
    LVL 1

    Author Comment

    by:mammouth
    Now i get:

    error C2819: type 'CInternetSession' does not have an overloaded member 'operator ->'

    If i replace the "->" with "." i get

    error C2440: 'initializing' : cannot convert from 'CStdioFile *' to 'CHttpFile *'

    Please help
    0
     
    LVL 86

    Expert Comment

    by:jkr
    >>error C2440: 'initializing' : cannot convert from 'CStdioFile *' to 'CHttpFile *'

    Um, 'OpenURL()' indeed returns that:

    CStdioFile* OpenURL( LPCTSTR pstrURL, DWORD dwContext = 1, DWORD dwFlags = INTERNET_FLAG_TRANSFER_ASCII, LPCTSTR pstrHeaders = NULL, DWORD dwHeadersLength = 0 );

    Are you thinking of

    CInternetSession session;
    CHttpConnection *httpConn = session.GetHttpConnection(...);
    CHttpFile *httpFile = httpConn->OpenRequest(...);

    ?

    0
     
    LVL 1

    Author Comment

    by:mammouth
    What i want to do, is get html content from a webpage into a variable like inet.openurl under vb.

    CInternetSession session;
    CHttpConnection *httpConn = session.GetHttpConnection(...);
    CHttpFile *httpFile = httpConn->OpenRequest(...);

    give me error:
    error C2661: 'CHttpConnection::OpenRequest' : no overloaded function takes 1 arguments

    0
     
    LVL 86

    Expert Comment

    by:jkr
    You'll need to supply the correct arguments. BTW,  you can read the content via a CStdioFile also:

    CInternetSession session;
    CStdioFile *httpFile = session.OpenURL("MonUrl/Mypage");
    httpFile->Close();
    0
     
    LVL 1

    Author Comment

    by:mammouth
    Which property of httpFile will contain content of MonUrl/Mypage ?

    This code give no error, but i can't found content anywhere?
    0
     
    LVL 86

    Accepted Solution

    by:
    You can read the contents of the page using

    CString str;

    while ( httpFile->ReadString(str)) {

    // process string here
    }
    0
     
    LVL 1

    Author Comment

    by:mammouth
    Does wininet will work behind a proxy?
    0
     
    LVL 86

    Expert Comment

    by:jkr
    Yes, it should.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
    IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    933 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now