百科解釋
DAV( http://www.webdav.org/ ) DAV不僅被看作HTTP的擴展,甚至被看作一種網(wǎng)絡(luò)文件系統(tǒng)(network filesystem ); A final goal of DAV is to leverage the success of HTTP in being a standard access layer for a wide range of storage repositories -- HTTP gave them read access, while DAV gives them write access. 當然,它不可能想本地文件系統(tǒng)一樣隨心所欲,它支持的操作還是有限的,以下三條: 1. 支持鎖定,Client可以先Lock Server上的file,然后操作; 2. 查找、定位,即DASL協(xié)議,DAV的一個子協(xié)議; 3. 拷貝、移動、創(chuàng)建、列舉,:不知道為什么叫做Namespace manipulation; 用FrontPage、Excess等打開、編輯遠程網(wǎng)站用的就是這個協(xié)議,它使得FrontPage可以編輯、覆蓋、刪除Server上的文件。 首先看看DASL協(xié)議是如何查找Server端的文件系統(tǒng): 最新草案:http://greenbytes.de/tech/webdav/draft-reschke-webdav-search-latest.html 總原則:使用Request發(fā)送XML格式的查詢字符串(Request-URI),得到Response,包含查詢結(jié)果(也是XML格式); Request-URL語法的一般形式: <d:searchrequest xmlns:d="DAV:"> <d:basicsearch> <d:select> <d:prop><d:getcontentlength/></d:prop> </d:select> <d:from> <d:scope> <d:href>/container1/</d:href> <d:depth>infinity</d:depth> </d:scope> </d:from> <d:where> <d:gt> <d:prop><d:getcontentlength/></d:prop> <d:literal>10000</d:literal> </d:gt> </d:where> <d:orderby> <d:order> <d:prop><d:getcontentlength/></d:prop> <d:ascending/> </d:order> </d:orderby> </d:basicsearch> </d:searchrequest> 對于DAV:SELECT 和 DAV:PROP的解釋在 http://www.ietf.org/rfc/rfc2518.txt 下面是獲取url下所有目錄、文件信息的C#代碼,目的就是組合一個 HTTP頭+Request-URL: // url指定Server端的檢索目錄,我認為也可以通過Request-URL的DAV:where部分來定: HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create(url); Request.Headers.Add("Translate: f"); Request.Credentials = CredentialCache.DefaultCredentials; string requestString = "<?xml version="1.0" encoding="utf-8" ?>"+ "<a:propfind xmlns:a="DAV:">"+ "<a:prop>"+ "<a:displayname/>"+ "<a:iscollection/>"+ "<a:getlastmodified/>"+ "</a:prop>"+ "</a:propfind>"; MessageBox.Show(requestString.ToString());// 只是顯示一下Request-URL Request.Method = "PROPFIND"; // 有 GET 、POST、PROPFIND..... if (deep == true) // 設(shè)定服務(wù)器上的檢索深度 Request.Headers.Add("Depth: infinity"); else Request.Headers.Add("Depth: 1"); Request.ContentLength = requestString.Length; Request.ContentType = "text/xml"; Stream requestStream = Request.GetRequestStream(); requestStream.Write(Encoding.ASCII.GetBytes(requestString),0,Encoding.ASCII.GetBytes(requestString).Length); requestStream.Close(); HttpWebResponse Response; StreamReader respStream; try { Response = (HttpWebResponse)Request.GetResponse(); respStream = new StreamReader(Response.GetResponseStream()); } catch (WebException e) { ..... }
移動通信網(wǎng) | 通信人才網(wǎng) | 更新日志 | 團隊博客 | 免責(zé)聲明 | 關(guān)于詞典 | 幫助