DavAddConnection example [modified]
-
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
-
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
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);
} -
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);
} -
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
-
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?.. :~
-
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?.. :~
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
-
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
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.". :^)
-
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.". :^)
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.
-
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
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...