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. Unable to make a successfull CHttpFile.SendRequest() call

Unable to make a successfull CHttpFile.SendRequest() call

Scheduled Pinned Locked Moved C / C++ / MFC
htmldatabasecomsysadminagentic-ai
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.
  • T Offline
    T Offline
    Terry ONolley
    wrote on last edited by
    #1

    I keep getting an error 500 returned (I do analyze the return value in the actual code - this is simplified). It does not throw an exception - I am reaching the server and if I download the returned page - I get the server-generated error HTML. Here is my code:

    void SomeClass::SomeFunction()
    {
    CInternetSession session("TheAgent");
    CHttpConnection* server = NULL;	
    CHttpFile* page;
    CString headers;
    CString& refheaders=headers; 
    DWORD dwRet;
    DWORD& refdwRet = dwRet;
    	
    try
    {
       server = session.GetHttpConnection("somewhere.com", (INTERNET_PORT)80); 
       page = server->OpenRequest(CHttpConnection::HTTP_VERB_GET, "http://somewhere.com/index.htm");
       
       headers = "Accept: text/*\r\nUser-Agent: TheAgent\r\n";
       page->AddRequestHeaders(refheaders);
       
       // ERROR CODE IS ALWAYS 500
       page->SendRequest();
       page->QueryInfoStatusCode(refdwRet);
       // ERROR CODE IS ALWAYS 500
    		
       if (dwRet == HTTP_STATUS_OK)
          MessageBox("SUCCESS");
       else
          MessageBox("ERROR"); 
    		
       delete page;	
       delete server;
    }
    catch (CInternetException* pEx)
    {
       MessageBox("CATCH");
    }
    	
    session.Close();
    } // exit function
    

    My server is running fine. I can take the same URL in the OpenRequest() call and paste it into the browser and the page loads just fine.

    H 1 Reply Last reply
    0
    • T Terry ONolley

      I keep getting an error 500 returned (I do analyze the return value in the actual code - this is simplified). It does not throw an exception - I am reaching the server and if I download the returned page - I get the server-generated error HTML. Here is my code:

      void SomeClass::SomeFunction()
      {
      CInternetSession session("TheAgent");
      CHttpConnection* server = NULL;	
      CHttpFile* page;
      CString headers;
      CString& refheaders=headers; 
      DWORD dwRet;
      DWORD& refdwRet = dwRet;
      	
      try
      {
         server = session.GetHttpConnection("somewhere.com", (INTERNET_PORT)80); 
         page = server->OpenRequest(CHttpConnection::HTTP_VERB_GET, "http://somewhere.com/index.htm");
         
         headers = "Accept: text/*\r\nUser-Agent: TheAgent\r\n";
         page->AddRequestHeaders(refheaders);
         
         // ERROR CODE IS ALWAYS 500
         page->SendRequest();
         page->QueryInfoStatusCode(refdwRet);
         // ERROR CODE IS ALWAYS 500
      		
         if (dwRet == HTTP_STATUS_OK)
            MessageBox("SUCCESS");
         else
            MessageBox("ERROR"); 
      		
         delete page;	
         delete server;
      }
      catch (CInternetException* pEx)
      {
         MessageBox("CATCH");
      }
      	
      session.Close();
      } // exit function
      

      My server is running fine. I can take the same URL in the OpenRequest() call and paste it into the browser and the page loads just fine.

      H Offline
      H Offline
      Hesham Amin
      wrote on last edited by
      #2

      Terry O`Nolley wrote: page = server->OpenRequest(CHttpConnection::HTTP_VERB_GET, "http://somewhere.com/index.htm"); OpenRequest should take the resourse name not the whole path page = server->OpenRequest(CHttpConnection::HTTP_VERB_GET, "index.htm")

      T 1 Reply Last reply
      0
      • H Hesham Amin

        Terry O`Nolley wrote: page = server->OpenRequest(CHttpConnection::HTTP_VERB_GET, "http://somewhere.com/index.htm"); OpenRequest should take the resourse name not the whole path page = server->OpenRequest(CHttpConnection::HTTP_VERB_GET, "index.htm")

        T Offline
        T Offline
        Terry ONolley
        wrote on last edited by
        #3

        THANK YOU!!!!!!!!!!!!! (5)

        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