How to disconnect (using CInternetSession, ChttpConnection, Chttpfile)

Posted on 2005-03-28
Medium Priority
Last Modified: 2008-01-09
Hello! I wanna develop a Http client program! I use three classes (CInternetSession, ChttpConnection, Chttpfile) for doing this! Now I can connect to my web LAN server, send request, and get the response. However, when it finished, I use functions Chttpfile::Close() ChttpConnection::Close(), and CInternetSession::Close() to disconnect to the server. But It doesn't work at all. I also "delete" theses three classes. But the connection still exists until the server disconnect this connection, or I shutdown the program. Is there any solution to disconnect it? Thank you very much!
Question by:appforce
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

WKalata earned 1500 total points
ID: 13671621
These classes are all able to (and in my experience, will from time to time) throw a CInternetException.
Try enclosing the code area that uses them with

  < WinInet code here>

and, below the try,

catch (CInternetException * pEx)

According to my documentation, calling Close() on all three of them should definately cause them all to disconnect.  In addition, if you delete any of them without calling Close, you might end up with some of your current problems.  In this event,  MFC will post some TRACE() messages to your debug window to inform you of such, so keep an eye on it.

Author Comment

ID: 13673970
Thank you for the answer! Sir! However, I tried the try & catch before, and it didn't catch any exception. I also calling Close on all three of them before I delete them. And I also use the callback function of the CInternetsession function. But it seems that the it never send the status of connection closed. It just seems that MFC doesn't implement the Close() function! Anyways, I am quite appreicating your answer! Thank you very much!  

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

762 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