Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. HTTP Connection question...

HTTP Connection question...

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpcomsysadminhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cabadam
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • C Cabadam

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      try this: try { http = net.GetHttpConnection("cabadam.homeip.net"); } catch(CInternetException *ex) { ...failed... ex->Delete(); } hope this helps

      C 1 Reply Last reply
      0
      • L Lost User

        try this: try { http = net.GetHttpConnection("cabadam.homeip.net"); } catch(CInternetException *ex) { ...failed... ex->Delete(); } hope this helps

        C Offline
        C Offline
        Cabadam
        wrote on last edited by
        #3

        Oh duh!! On the catch, I had the pEx as CInternetException, not CInternetException* That did it... thx Adam cabadam@houston.rr.com

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups