HTTP Connection question...
-
I am using CInternetSession, CHttpConnection, and CHttpFile to get a file from an HTTP server. I am having a problem though determining if the initial connection succeeded or not. If the server is 'off' then the code seems to execute despite my 'ifs' and produces an exception. If I put the statement throwing the exception into a try-catch, it isn't caught, and crashes the program anyway. CInternetSession net; CHttpConnection* http = NULL; CHttpFile* file = NULL; http = net.GetHttpConnection("cabadam.homeip.net"); if (http == NULL) { status += "Failed to connect to server!\r\n"; dlg->edit_status.SetWindowText(status); dlg->GetDlgItem(IDC_BUTTON_CONTINUE)->EnableWindow(1); return 1; } file = http->OpenRequest(CHttpConnection::HTTP_VERB_GET,"version.txt"); try { file->SendRequest(); //THIS STATEMENT crashes the program even though it is inside a try catch } catch (CInternetException pEx) { status += "Failed to connect to server!\r\n"; dlg->edit_status.SetWindowText(status); dlg->GetDlgItem(IDC_BUTTON_CONTINUE)->EnableWindow(1); return 1; } I have tried several different things, but I haven't been able to figure out how to determine if it was unable to connect with the server. Am I doing something wrong? Or is there an easier way to do this? Thanks! Adam cabadam@houston.rr.com
-
I am using CInternetSession, CHttpConnection, and CHttpFile to get a file from an HTTP server. I am having a problem though determining if the initial connection succeeded or not. If the server is 'off' then the code seems to execute despite my 'ifs' and produces an exception. If I put the statement throwing the exception into a try-catch, it isn't caught, and crashes the program anyway. CInternetSession net; CHttpConnection* http = NULL; CHttpFile* file = NULL; http = net.GetHttpConnection("cabadam.homeip.net"); if (http == NULL) { status += "Failed to connect to server!\r\n"; dlg->edit_status.SetWindowText(status); dlg->GetDlgItem(IDC_BUTTON_CONTINUE)->EnableWindow(1); return 1; } file = http->OpenRequest(CHttpConnection::HTTP_VERB_GET,"version.txt"); try { file->SendRequest(); //THIS STATEMENT crashes the program even though it is inside a try catch } catch (CInternetException pEx) { status += "Failed to connect to server!\r\n"; dlg->edit_status.SetWindowText(status); dlg->GetDlgItem(IDC_BUTTON_CONTINUE)->EnableWindow(1); return 1; } I have tried several different things, but I haven't been able to figure out how to determine if it was unable to connect with the server. Am I doing something wrong? Or is there an easier way to do this? Thanks! Adam cabadam@houston.rr.com
try this: try { http = net.GetHttpConnection("cabadam.homeip.net"); } catch(CInternetException *ex) { ...failed... ex->Delete(); } hope this helps
-
try this: try { http = net.GetHttpConnection("cabadam.homeip.net"); } catch(CInternetException *ex) { ...failed... ex->Delete(); } hope this helps
Oh duh!! On the catch, I had the pEx as CInternetException, not CInternetException* That did it... thx Adam cabadam@houston.rr.com