我正在尝试将文件上传到共享点。授权工作正常,但最终以 statusOK
而不是CREATED
. 最终不会创建文件。我不明白为什么会这样,因为我使用了似乎对其他人有用的方法(没有抱怨)。这是我正在使用的代码:
Public Sub Create()
Dim szURL1 = "http://host.domain.com/p/projects/4/Proposal/cze.txt"
Dim szContent = String.Format("Date/Time: {0} {1}", DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString())
'Define username and password strings.
Dim domain = "DOMAIN_NAME"
Dim szUsername = "USER_NAME"
Dim szPassword = "PASSWORD"
Dim httpPutRequest As HttpWebRequest = DirectCast(WebRequest.Create(szURL1), HttpWebRequest)
httpPutRequest.Credentials = New NetworkCredential(szUsername, szPassword, domain)
httpPutRequest.PreAuthenticate = True
httpPutRequest.Method = "PUT"
httpPutRequest.Headers.Add("Overwrite", "T")
httpPutRequest.ContentLength = szContent.Length
'Optional, but allows for larger files.
httpPutRequest.SendChunked = True
Dim requestStream = httpPutRequest.GetRequestStream()
'Write the string to the destination as a text file.
requestStream.Write(System.Text.Encoding.UTF8.GetBytes(DirectCast(szContent, String)), 0, szContent.Length)
'Close the request stream.
requestStream.Close()
'Retrieve the response.
Dim httpPutResponse As HttpWebResponse = DirectCast(httpPutRequest.GetResponse(), HttpWebResponse)
Debug.WriteLine("PUT Response #1: {0}", httpPutResponse.StatusDescription)
End Sub
这产生:PUT Response #1: OK
而不是PUT Response #1: CREATED
我把代码从: http: //blogs.iis.net/robert_mcmurray/archive/2010/02/09/sending-webdav-requests-in-net.aspx翻译成VB,但我不认为翻译是问题所在。
有任何想法吗?
编辑:我检查了原始 C# 代码,结果是一样的。可能是什么问题呢?