使用WebDav通过代理上传到SharePoint的HTTP 405失败
本文关键字:SharePoint HTTP 失败 WebDav 代理 使用 | 更新日期: 2023-09-27 17:50:48
我试图通过使用WebClient和WebDav . net库从independentsoft上传一个文件到SharePoint库。首先,我遇到了Upload-method返回HTTP 403异常的问题。然后我意识到我必须通过代理人。现在返回HTTP 405。我也使用了clienttom,但无法在那里配置代理设置,所以我仍然在那里得到HTTP 403。
我为WebClient和WebDav .NET使用的代码如下:
WebClient:
webClient.UseDefaultCredentials = true;
string[] bypassList = { "localhost" };
webClient.Proxy = new WebProxy("proxy", true, bypassList, new NetworkCredential("user", "password"));
try
{
byte[] response = webClient.UploadFile("http://sharepoint/testBlankSite/testLibrary/TestUpload.txt", "PUT", @"...'Desktop'TestUpload.txt");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
WebDav。net
NetworkCredential credential = new NetworkCredential("user", "password");
string[] bypassList = { "localhost" };
WebProxy proxy = new WebProxy("proxy", true, bypassList, new NetworkCredential("user", "password"));
WebdavSession session = new WebdavSession(credential, proxy);
Resource resource = new Resource(session);
try
{
resource.Upload("http://sharepoint/testBlankSite/testLibrary/TestUpload.txt", @"...'Desktop'TestUpload.txt");
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
有没有人知道为什么这是不工作,我怎么能解决这个问题?
这是SharePoint的一个很常见的问题。查看这些链接:
SharePoint、WebDAV和405个状态码示例
SharePoint 2013 -在SharePoint上禁用WebDAV
正如@GavinB和@Jeremy所提到的,备选方案是客户端对象模型,即Microsoft.SharePoint.Client。这个库只是一个包装器,它执行与您正在尝试的请求类似的HTTP请求。