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

How to disconnect (using CInternetSession, ChttpConnection, Chttpfile)

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!
0
appforce
Asked:
appforce
1 Solution
 
WKalataCommented:
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

try
{
  < WinInet code here>
}

and, below the try,

catch (CInternetException * pEx)
{
  pEx->ReportError();
  pEx->Delete();
}

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.
0
 
appforceAuthor Commented:
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!  
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

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