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. AfxParseURL

AfxParseURL

Scheduled Pinned Locked Moved C / C++ / MFC
com
10 Posts 6 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.
  • S Offline
    S Offline
    shuchigo_jane
    wrote on last edited by
    #1

    Can anyone please point out why the AfxParseURL function is not working 4 me.. i've used it as: CString URL=("http://www.yahoo.com"); BOOL bParse; CString csSvrName; CString csObjName; INTERNET_PORT nPort; DWORD dwServiceType = AFX_INET_SERVICE_HTTP; bParse=AfxParseURL( URL, dwServiceType , csSvrName, csObjName, nPort );

    C 1 Reply Last reply
    0
    • S shuchigo_jane

      Can anyone please point out why the AfxParseURL function is not working 4 me.. i've used it as: CString URL=("http://www.yahoo.com"); BOOL bParse; CString csSvrName; CString csObjName; INTERNET_PORT nPort; DWORD dwServiceType = AFX_INET_SERVICE_HTTP; bParse=AfxParseURL( URL, dwServiceType , csSvrName, csObjName, nPort );

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      shuchigo_jane wrote:

      why the AfxParseURL function is not working 4 me

      What is the problem ?


      Cédric Moonen Software developer
      Charting control

      S 1 Reply Last reply
      0
      • C Cedric Moonen

        shuchigo_jane wrote:

        why the AfxParseURL function is not working 4 me

        What is the problem ?


        Cédric Moonen Software developer
        Charting control

        S Offline
        S Offline
        shuchigo_jane
        wrote on last edited by
        #3

        nothing wrong with d code then? it gives me a "debug assertion failed" message,plus no value returned in bParse..

        C T S D 4 Replies Last reply
        0
        • S shuchigo_jane

          nothing wrong with d code then? it gives me a "debug assertion failed" message,plus no value returned in bParse..

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          shuchigo_jane wrote:

          it gives me a "debug assertion failed" message

          And how are you sure that this is this code that causes the crash ? Use your debugger yo track the crash (press F5 to start and F9 to set breakpoints).


          Cédric Moonen Software developer
          Charting control

          1 Reply Last reply
          0
          • S shuchigo_jane

            nothing wrong with d code then? it gives me a "debug assertion failed" message,plus no value returned in bParse..

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            shuchigo_jane wrote:

            it gives me a "debug assertion failed" message,plus no value returned in bParse..

            On first look there is no error in code, have check what line no is DEBUGGER showing you assertion!

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta VC Forum Q&A :- I/ IV

            1 Reply Last reply
            0
            • S shuchigo_jane

              nothing wrong with d code then? it gives me a "debug assertion failed" message,plus no value returned in bParse..

              S Offline
              S Offline
              shuchigo_jane
              wrote on last edited by
              #6

              will this detailed code help tracking it?? CInternetSession session("My Session"); CHttpConnection* pServer = NULL; CString tmpstr; char inbuff[100000]; UINT nBytesRead; CHttpFile* pFile = NULL; try { void *szBuff=NULL; CString URL=("http://www.yahoo.com"); BOOL bParse; CString csSvrName; CString csObjName; INTERNET_PORT nPort; DWORD dwServiceType = AFX_INET_SERVICE_HTTP; bParse=AfxParseURL( URL, dwServiceType , csSvrName, csObjName, nPort ); pServer = session.GetHttpConnection( csSvrName, nPort); pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, url); pFile->AddRequestHeaders(pBuf); pFile->SendRequest(); UINT nRead = pFile->Read(szBuff, 1023); while (nRead > 0) { //read file... } delete pFile; delete pServer; } catch (CInternetException* pEx) { LPTSTR lpszError=NULL; //catch errors from WinInet pEx->GetErrorMessagelpszError,1023); } if(pFile==NULL) { AfxMessageBox("Error in openurl"); } else { nBytesRead=pFile->Read(inbuff,sizeof(inbuff)); tmpstr.Format("Read %d",nBytesRead); AfxMessageBox(tmpstr); }// endif session.Close();

              C M 2 Replies Last reply
              0
              • S shuchigo_jane

                will this detailed code help tracking it?? CInternetSession session("My Session"); CHttpConnection* pServer = NULL; CString tmpstr; char inbuff[100000]; UINT nBytesRead; CHttpFile* pFile = NULL; try { void *szBuff=NULL; CString URL=("http://www.yahoo.com"); BOOL bParse; CString csSvrName; CString csObjName; INTERNET_PORT nPort; DWORD dwServiceType = AFX_INET_SERVICE_HTTP; bParse=AfxParseURL( URL, dwServiceType , csSvrName, csObjName, nPort ); pServer = session.GetHttpConnection( csSvrName, nPort); pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, url); pFile->AddRequestHeaders(pBuf); pFile->SendRequest(); UINT nRead = pFile->Read(szBuff, 1023); while (nRead > 0) { //read file... } delete pFile; delete pServer; } catch (CInternetException* pEx) { LPTSTR lpszError=NULL; //catch errors from WinInet pEx->GetErrorMessagelpszError,1023); } if(pFile==NULL) { AfxMessageBox("Error in openurl"); } else { nBytesRead=pFile->Read(inbuff,sizeof(inbuff)); tmpstr.Format("Read %d",nBytesRead); AfxMessageBox(tmpstr); }// endif session.Close();

                C Offline
                C Offline
                Cedric Moonen
                wrote on last edited by
                #7

                Please use your debugger to check where it crashes. Then, if you are not able to correct the problem, give us detailed information about the crash (where it crashes, what the problem is, ...)


                Cédric Moonen Software developer
                Charting control

                1 Reply Last reply
                0
                • S shuchigo_jane

                  will this detailed code help tracking it?? CInternetSession session("My Session"); CHttpConnection* pServer = NULL; CString tmpstr; char inbuff[100000]; UINT nBytesRead; CHttpFile* pFile = NULL; try { void *szBuff=NULL; CString URL=("http://www.yahoo.com"); BOOL bParse; CString csSvrName; CString csObjName; INTERNET_PORT nPort; DWORD dwServiceType = AFX_INET_SERVICE_HTTP; bParse=AfxParseURL( URL, dwServiceType , csSvrName, csObjName, nPort ); pServer = session.GetHttpConnection( csSvrName, nPort); pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, url); pFile->AddRequestHeaders(pBuf); pFile->SendRequest(); UINT nRead = pFile->Read(szBuff, 1023); while (nRead > 0) { //read file... } delete pFile; delete pServer; } catch (CInternetException* pEx) { LPTSTR lpszError=NULL; //catch errors from WinInet pEx->GetErrorMessagelpszError,1023); } if(pFile==NULL) { AfxMessageBox("Error in openurl"); } else { nBytesRead=pFile->Read(inbuff,sizeof(inbuff)); tmpstr.Format("Read %d",nBytesRead); AfxMessageBox(tmpstr); }// endif session.Close();

                  M Offline
                  M Offline
                  Mila025
                  wrote on last edited by
                  #8

                  When you trying to read: ... UINT nRead = pFile->Read(szBuff, 1023); ... your szBuff is NULL - initialize this buffer (i.e.: szBuff = new BYTE[1023]). ----------- Mila

                  A 1 Reply Last reply
                  0
                  • M Mila025

                    When you trying to read: ... UINT nRead = pFile->Read(szBuff, 1023); ... your szBuff is NULL - initialize this buffer (i.e.: szBuff = new BYTE[1023]). ----------- Mila

                    A Offline
                    A Offline
                    alan top
                    wrote on last edited by
                    #9

                    { ShowBanner(); if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { cerr << _T("MFC Failed to initialize.\n"); return 1; } if (argc < 2 || !ParseOptions(argc, argv) || pszURL == NULL) ShowUsage(); int nRetCode = 0; CTearSession session(_T("TEAR - MFC Sample App"), dwAccessType); CHttpConnection* pServer = NULL; CHttpFile* pFile = NULL; try { // check to see if this is a reasonable URL CString strServerName; CString strObject; INTERNET_PORT nPort; DWORD dwServiceType; if (!AfxParseURL(pszURL, dwServiceType, strServerName, strObject, nPort) || dwServiceType != INTERNET_SERVICE_HTTP) { cerr << _T("Error: can only use URLs beginning with http://") << endl; ThrowTearException(1); } if (bProgressMode) { cerr << _T("Opening Internet..."); VERIFY(session.EnableStatusCallback(TRUE)); } pServer = session.GetHttpConnection(strServerName, nPort); pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags); pFile->AddRequestHeaders(szHeaders); pFile->SendRequest(); DWORD dwRet; pFile->QueryInfoStatusCode(dwRet); // if access was denied, prompt the user for the password if (dwRet == HTTP_STATUS_DENIED) { DWORD dwPrompt; dwPrompt = pFile->ErrorDlg(NULL, ERROR_INTERNET_INCORRECT_PASSWORD, FLAGS_ERROR_UI_FLAGS_GENERATE_DATA | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL); // if the user cancelled the dialog, bail out if (dwPrompt != ERROR_INTERNET_FORCE_RETRY) { cerr << _T("Access denied: Invalid password\n"); ThrowTearException(1); } pFile->SendRequest(); pFile->QueryInfoStatusCode(dwRet); } CString strNewLocation; pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation); // were we redirected? // these response status codes come from WININET.H if (dwRet == HTTP_STATUS_MOVED || dwRet == HTTP_STATUS_REDIRECT || dwRet == HTTP_STATUS_REDIRECT_METHOD) { CString strNewLocation; pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation); int nPlace = strNewLocation.Find(_T("Location: ")); if (nPlace == -1) { cerr << _T("Error: Site redirects with no new location") << endl; ThrowTearException(2); } strNewLocation = strNewLocation.Mid(nPlace + 10); nPlace = strNewLocation.Find('\n'); if (nPlace > 0) strNewLocation = strNewLocation.Left(nPlace); // close up the redirected site

                    1 Reply Last reply
                    0
                    • S shuchigo_jane

                      nothing wrong with d code then? it gives me a "debug assertion failed" message,plus no value returned in bParse..

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      shuchigo_jane wrote:

                      it gives me a "debug assertion failed" message...

                      Knowing what line of what file would go a long way towards solving the problem.


                      "The largest fire starts but with the smallest spark." - David Crow

                      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