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. DavAddConnection example [modified]

DavAddConnection example [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminsecuritycryptographyhelptutorial
10 Posts 3 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
    ShadowUz
    wrote on last edited by
    #1

    Hello guys! I have to connect to WebDAV Server, example: http://webdav.pspace.co.kr But I cannot find any code example for DavAddConnection Function. And, in MSDN I found this: "Use this function when you are connecting to a WebDAV server using the Secure Sockets Layer (SSL) protocol and therefore must specify a certificate. To connect to a WebDAV server without specifying a certificate, use a Windows networking function such as WNetAddConnection2 or WNetAddConnection3." Does anyone know some examples of DavAddConnection? Found some code examples for WNetAddConnection2 and tried to connect, but, unsuccessfully.

    CString passW=_T("pwd123");
    CString userN=_T("user1");
    CString locname=_T("webdav.pspace.co.kr");
    DWORD dwRetVal;

    NETRESOURCE nr;
    DWORD dwFlags;
    memset(&nr, 0, sizeof (NETRESOURCE));

    nr.dwType = RESOURCETYPE_ANY;
    nr.lpLocalName = (LPTSTR)((LPCTSTR)locname);
    nr.lpRemoteName = (LPTSTR)((LPCTSTR)locname);
    nr.lpProvider = NULL;
    dwFlags = CONNECT_UPDATE_PROFILE;
    dwRetVal = WNetAddConnection2(&nr, passW, userN, FALSE);

    if (dwRetVal == NO_ERROR)
    AfxMessageBox(_T("Connection added to"));
    else
    AfxMessageBox(_T("Error"));

    I'm getting "Error". By the way, I'm I doing right trying to connect to WebDAV server via this technic? Thank you.

    modified on Thursday, January 20, 2011 8:30 PM

    A M 3 Replies Last reply
    0
    • S ShadowUz

      Hello guys! I have to connect to WebDAV Server, example: http://webdav.pspace.co.kr But I cannot find any code example for DavAddConnection Function. And, in MSDN I found this: "Use this function when you are connecting to a WebDAV server using the Secure Sockets Layer (SSL) protocol and therefore must specify a certificate. To connect to a WebDAV server without specifying a certificate, use a Windows networking function such as WNetAddConnection2 or WNetAddConnection3." Does anyone know some examples of DavAddConnection? Found some code examples for WNetAddConnection2 and tried to connect, but, unsuccessfully.

      CString passW=_T("pwd123");
      CString userN=_T("user1");
      CString locname=_T("webdav.pspace.co.kr");
      DWORD dwRetVal;

      NETRESOURCE nr;
      DWORD dwFlags;
      memset(&nr, 0, sizeof (NETRESOURCE));

      nr.dwType = RESOURCETYPE_ANY;
      nr.lpLocalName = (LPTSTR)((LPCTSTR)locname);
      nr.lpRemoteName = (LPTSTR)((LPCTSTR)locname);
      nr.lpProvider = NULL;
      dwFlags = CONNECT_UPDATE_PROFILE;
      dwRetVal = WNetAddConnection2(&nr, passW, userN, FALSE);

      if (dwRetVal == NO_ERROR)
      AfxMessageBox(_T("Connection added to"));
      else
      AfxMessageBox(_T("Error"));

      I'm getting "Error". By the way, I'm I doing right trying to connect to WebDAV server via this technic? Thank you.

      modified on Thursday, January 20, 2011 8:30 PM

      A Offline
      A Offline
      Andrew Brock
      wrote on last edited by
      #2

      Use this to see what error you are getting. That may shed some light on what may be causing it

      if (dwRetVal == NO_ERROR)
      AfxMessageBox(_T("Connection added to"));
      else {
      TCHAR szError[32];
      _stprintf(szError, _T("Error %u"), dwRetVal);
      AfxMessageBox(szError);
      }

      S 1 Reply Last reply
      0
      • A Andrew Brock

        Use this to see what error you are getting. That may shed some light on what may be causing it

        if (dwRetVal == NO_ERROR)
        AfxMessageBox(_T("Connection added to"));
        else {
        TCHAR szError[32];
        _stprintf(szError, _T("Error %u"), dwRetVal);
        AfxMessageBox(szError);
        }

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

        Thanks for the reply. I'm getting "Error 487".

        A 1 Reply Last reply
        0
        • S ShadowUz

          Thanks for the reply. I'm getting "Error 487".

          A Offline
          A Offline
          Andrew Brock
          wrote on last edited by
          #4

          MSDN[^] says

          Error Name: ERROR_INVALID_ADDRESS
          Error Code: 487 (0x1E7)
          Error Text: Attempt to access invalid address.

          1 Reply Last reply
          0
          • S ShadowUz

            Hello guys! I have to connect to WebDAV Server, example: http://webdav.pspace.co.kr But I cannot find any code example for DavAddConnection Function. And, in MSDN I found this: "Use this function when you are connecting to a WebDAV server using the Secure Sockets Layer (SSL) protocol and therefore must specify a certificate. To connect to a WebDAV server without specifying a certificate, use a Windows networking function such as WNetAddConnection2 or WNetAddConnection3." Does anyone know some examples of DavAddConnection? Found some code examples for WNetAddConnection2 and tried to connect, but, unsuccessfully.

            CString passW=_T("pwd123");
            CString userN=_T("user1");
            CString locname=_T("webdav.pspace.co.kr");
            DWORD dwRetVal;

            NETRESOURCE nr;
            DWORD dwFlags;
            memset(&nr, 0, sizeof (NETRESOURCE));

            nr.dwType = RESOURCETYPE_ANY;
            nr.lpLocalName = (LPTSTR)((LPCTSTR)locname);
            nr.lpRemoteName = (LPTSTR)((LPCTSTR)locname);
            nr.lpProvider = NULL;
            dwFlags = CONNECT_UPDATE_PROFILE;
            dwRetVal = WNetAddConnection2(&nr, passW, userN, FALSE);

            if (dwRetVal == NO_ERROR)
            AfxMessageBox(_T("Connection added to"));
            else
            AfxMessageBox(_T("Error"));

            I'm getting "Error". By the way, I'm I doing right trying to connect to WebDAV server via this technic? Thank you.

            modified on Thursday, January 20, 2011 8:30 PM

            A Offline
            A Offline
            Andrew Brock
            wrote on last edited by
            #5

            Check out your last parameter in WNetAddConnection2(&nr, passW, userN, FALSE); According to MSDN[^] 0 is not a legal value for the parameter dwFlags and FALSE is #define FALSE 0. Did you mean to pass in your variable dwFlags? (in the sample on MSDN they do)

            S 1 Reply Last reply
            0
            • A Andrew Brock

              Check out your last parameter in WNetAddConnection2(&nr, passW, userN, FALSE); According to MSDN[^] 0 is not a legal value for the parameter dwFlags and FALSE is #define FALSE 0. Did you mean to pass in your variable dwFlags? (in the sample on MSDN they do)

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

              Hello. I have tried a couple of thing to make the code work. But, still, I cannot connect to our WebDAV server "webdav.pspace.co.kr". :confused: But, using the code shown below, I'm getting a positive answer: "Connection added to":

              CString locname=_T("\\\\www.barracudaserver.com\\dav\\");
              DWORD dwRetVal;
              NETRESOURCE nr;
              DWORD dwFlags;
              memset(&nr, 0, sizeof (NETRESOURCE));

              nr.dwScope=RESOURCE_GLOBALNET;
              nr.dwType = RESOURCETYPE_ANY;
              nr.lpLocalName = NULL;
              nr.lpRemoteName = (LPTSTR)((LPCTSTR)locname);
              nr.lpProvider = _T("");

              dwFlags = CONNECT_UPDATE_PROFILE;
              dwRetVal = WNetAddConnection2(&nr, _T(""), _T(""), dwFlags);

              if (dwRetVal == NO_ERROR)
              {
              AfxMessageBox(_T("Connection added to"));
              }
              else
              {
              TCHAR szError[32];
              _stprintf(szError, _T("Error %u"), dwRetVal);
              AfxMessageBox(szError);
              }

              In the case of locname=_T("\\\\webdav.pspace.co.kr\\") the result is "Error 53:", which means "The network path you specified is not found." May be something is wrong with the server or may be I'm using the wrong approach. Any ideas?.. :~

              A 1 Reply Last reply
              0
              • S ShadowUz

                Hello. I have tried a couple of thing to make the code work. But, still, I cannot connect to our WebDAV server "webdav.pspace.co.kr". :confused: But, using the code shown below, I'm getting a positive answer: "Connection added to":

                CString locname=_T("\\\\www.barracudaserver.com\\dav\\");
                DWORD dwRetVal;
                NETRESOURCE nr;
                DWORD dwFlags;
                memset(&nr, 0, sizeof (NETRESOURCE));

                nr.dwScope=RESOURCE_GLOBALNET;
                nr.dwType = RESOURCETYPE_ANY;
                nr.lpLocalName = NULL;
                nr.lpRemoteName = (LPTSTR)((LPCTSTR)locname);
                nr.lpProvider = _T("");

                dwFlags = CONNECT_UPDATE_PROFILE;
                dwRetVal = WNetAddConnection2(&nr, _T(""), _T(""), dwFlags);

                if (dwRetVal == NO_ERROR)
                {
                AfxMessageBox(_T("Connection added to"));
                }
                else
                {
                TCHAR szError[32];
                _stprintf(szError, _T("Error %u"), dwRetVal);
                AfxMessageBox(szError);
                }

                In the case of locname=_T("\\\\webdav.pspace.co.kr\\") the result is "Error 53:", which means "The network path you specified is not found." May be something is wrong with the server or may be I'm using the wrong approach. Any ideas?.. :~

                A Offline
                A Offline
                Andrew Brock
                wrote on last edited by
                #7

                Running your code with locname=_T("\\\\webdav.pspace.co.kr\\") and running a packet sniffer I get the response

                <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
                <html><head>
                <title>401 Authorization Required</title>
                </head><body>
                <h1>Authorization Required</h1>
                <p>This server could not verify that you
                are authorized to access the document
                requested. Either you supplied the wrong
                credentials (e.g., bad password), or your
                browser doesn't understand how to supply
                the credentials required.</p>
                <hr>
                <address>Apache Server at webdav.pspace.co.kr Port 80</address>
                </body></html>

                I'm sure you can figure out what the problem is from the response :D

                S 1 Reply Last reply
                0
                • A Andrew Brock

                  Running your code with locname=_T("\\\\webdav.pspace.co.kr\\") and running a packet sniffer I get the response

                  <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
                  <html><head>
                  <title>401 Authorization Required</title>
                  </head><body>
                  <h1>Authorization Required</h1>
                  <p>This server could not verify that you
                  are authorized to access the document
                  requested. Either you supplied the wrong
                  credentials (e.g., bad password), or your
                  browser doesn't understand how to supply
                  the credentials required.</p>
                  <hr>
                  <address>Apache Server at webdav.pspace.co.kr Port 80</address>
                  </body></html>

                  I'm sure you can figure out what the problem is from the response :D

                  S Offline
                  S Offline
                  ShadowUz
                  wrote on last edited by
                  #8

                  Dear Andrew! Thanks for your help! I'm sorry for being pesky and dumb. I can connect to the server using browser with username and password. But, I'm not being able to do it using my app. Still I get the same error: "The network path you specified is not found.". :^)

                  A 1 Reply Last reply
                  0
                  • S ShadowUz

                    Dear Andrew! Thanks for your help! I'm sorry for being pesky and dumb. I can connect to the server using browser with username and password. But, I'm not being able to do it using my app. Still I get the same error: "The network path you specified is not found.". :^)

                    A Offline
                    A Offline
                    Andrew Brock
                    wrote on last edited by
                    #9

                    I have never used WNetAddConnection2, and what I have been telling you is from reading MSDN and running your code on my computer so i dont know of any reasons that this might be hapening. Since i dont have an account on webdav.pspace.co.kr[^] the best i can offer is that you run Wireshark[^] and start the sniffer while you try to connect to the server to see what the server is sending back to you.

                    1 Reply Last reply
                    0
                    • S ShadowUz

                      Hello guys! I have to connect to WebDAV Server, example: http://webdav.pspace.co.kr But I cannot find any code example for DavAddConnection Function. And, in MSDN I found this: "Use this function when you are connecting to a WebDAV server using the Secure Sockets Layer (SSL) protocol and therefore must specify a certificate. To connect to a WebDAV server without specifying a certificate, use a Windows networking function such as WNetAddConnection2 or WNetAddConnection3." Does anyone know some examples of DavAddConnection? Found some code examples for WNetAddConnection2 and tried to connect, but, unsuccessfully.

                      CString passW=_T("pwd123");
                      CString userN=_T("user1");
                      CString locname=_T("webdav.pspace.co.kr");
                      DWORD dwRetVal;

                      NETRESOURCE nr;
                      DWORD dwFlags;
                      memset(&nr, 0, sizeof (NETRESOURCE));

                      nr.dwType = RESOURCETYPE_ANY;
                      nr.lpLocalName = (LPTSTR)((LPCTSTR)locname);
                      nr.lpRemoteName = (LPTSTR)((LPCTSTR)locname);
                      nr.lpProvider = NULL;
                      dwFlags = CONNECT_UPDATE_PROFILE;
                      dwRetVal = WNetAddConnection2(&nr, passW, userN, FALSE);

                      if (dwRetVal == NO_ERROR)
                      AfxMessageBox(_T("Connection added to"));
                      else
                      AfxMessageBox(_T("Error"));

                      I'm getting "Error". By the way, I'm I doing right trying to connect to WebDAV server via this technic? Thank you.

                      modified on Thursday, January 20, 2011 8:30 PM

                      M Offline
                      M Offline
                      micktsai
                      wrote on last edited by
                      #10

                      Hi, you might want to check out this part nr.lpLocalName = (LPTSTR)((LPCTSTR)locname); based on MSDN: http://msdn.microsoft.com/en-us/library/aa385413(v=vs.85).aspx[^] lpLocalName should be NULL in you case "A pointer to a null-terminated string that specifies the name of a local device to redirect, such as "F:" or "LPT1". The string is treated in a case-insensitive manner." but you use webdav.pspace.co.kr, which may cause the problem I think...

                      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