0
데비안 리눅스에 WebDAV 서버를 설치했습니다. FireFox와 IE를 사용하여 데비안 리눅스에 연결할 수 있기 때문에이 데비안 리눅스에 WebDAV 서버를 설치했습니다. 나는 다음과 같은 코드로 연결하려고하면서C# 응용 프로그램에서 webDav 폴더에 액세스 할 때 권한이없는 401 오류가 발생합니까?
는하지만, 그것은 반환 동일한 자격 증명이 작동하는 동안
"The remote server returned and error:(401) Unauthorized error"
try
{
// Build the SQL query.
strQuery = "<?xml version=\"1.0\"?><D:searchrequest xmlns:D = \"DAV:\" >";
strQuery += "<D:sql>SELECT \"DAV:href\" FROM scope('hierarchical traversal of \"";
strQuery += strRootURI + "\"')</D:sql></D:searchrequest>";
// Create a new CredentialCache object and fill it with the network
// credentials required to access the server.
MyCredentialCache = new System.Net.CredentialCache();
MyCredentialCache.Add(new System.Uri(strRootURI),
"NTLM",
new System.Net.NetworkCredential(strUserName, strPassword)
);
// Create the HttpWebRequest object.
Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);
// Add the network credentials to the request.
Request.Credentials = MyCredentialCache;
// Specify the method.
Request.Method = "SEARCH";
// Encode the body using UTF-8.
bytes = Encoding.UTF8.GetBytes((string)strQuery);
// Set the content header length. This must be
// done before writing data to the request stream.
Request.ContentLength = bytes.Length;
// Get a reference to the request stream.
RequestStream = Request.GetRequestStream();
// Write the SQL query to the request stream.
RequestStream.Write(bytes, 0, bytes.Length);
// Close the Stream object to release the connection
// for further use.
RequestStream.Close();
// Set the content type header.
Request.ContentType = "text/xml";
// Send the SEARCH method request and get the
// response from the server.
Response = (HttpWebResponse)Request.GetResponse();
// Get the XML response stream.
ResponseStream = Response.GetResponseStream();
// Create the XmlTextReader object from the XML
// response stream.
XmlReader = new XmlTextReader(ResponseStream);
// Read through the XML response, node by node.
while (XmlReader.Read())
{
// Look for the opening DAV:href node. The DAV: namespace is
//typically assigned the a: prefix in the XML response body.
if (XmlReader.Name == "a:href")
{
// Advance the reader to the text node.
XmlReader.Read();
// Display the value of the DAV:href text node.
Console.WriteLine("Value: " + XmlReader.Value);
Console.WriteLine("");
//Advance the reader to the closing DAV:href node.
XmlReader.Read();
}
}
// Clean up.
XmlReader.Close();
ResponseStream.Close();
Response.Close();
}
내가 anuathorized 오류가 일어나는 이유를 이해 할 수없는입니다 throgh 웹 브라우저. 도메인이 있으므로 도메인 입력란을 비워 둡니다.
인증 유형 NLTM
또는 다른 것입니까? 도와주세요 .
감사합니다,
Subhen
http://stackoverflow.com/questions/3137995/sample-code-for-profind/3148449 # 3148449 401을 언급하지 않았습니다. –