使用 .NET WebRequest 将文件上传到共享点时出现 409/冲突 HTTP 错误的原因?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6785036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:44:45  来源:igfitidea点击:

Reasons for a 409/Conflict HTTP error when uploading a file to sharepoint using a .NET WebRequest?

.netsharepointhttpwebrequestwebrequest

提问by GR7

I've got a method that uses a WebRequest to upload a file to a sharepoint 2010 list/folder, using a PUT request, with the Overwrite Header set to T (overwrite).

我有一种方法,它使用 WebRequest 将文件上传到 sharepoint 2010 列表/文件夹,使用 PUT 请求,并将 Overwrite Header 设置为 T(覆盖)。

When several files are uploaded (method is called several times), some requests fail with a 409 Conflict HTTP error.

上传多个文件时(多次调用该方法),某些请求会因 409 冲突 HTTP 错误而失败。

I've googled, and it seems the most common reason is trying to affect/update a file that does not exist (like setting the request URL to a path without a file name). However, that is not the case. In case the conflict had something to do with the file already existing, I added code to physically delete the file before uploading it, and i'm still getting some 409's.

我用谷歌搜索过,似乎最常见的原因是试图影响/更新一个不存在的文件(比如将请求 URL 设置为没有文件名的路径)。然而,事实并非如此。如果冲突与已经存在的文件有关,我添加了代码以在上传文件之前物理删除文件,但我仍然收到一些 409。

Has anyone received this type of error, and if so, can you tell me how you fixed it and what was the root cause? Any help is greatly appreciated. Thanks

有没有人收到过这种类型的错误,如果有,你能告诉我你是如何修复它的以及根本原因是什么吗?任何帮助是极大的赞赏。谢谢

采纳答案by GR7

Since no answers were posted, I found the following here:

由于没有发布答案,我在这里找到了以下内容:

The Web server (running the Web site) thinks that the request submitted by the client (e.g. your Web browser or our CheckUpDown robot) can not be completed because it conflicts with some rule already established. For example, you may get a 409 error if you try to upload a file to the Web server which is older than the one already there - resulting in a version control conflict.

Web 服务器(运行网站)认为客户端(例如您的 Web 浏览器或我们的 CheckUpDown 机器人)提交的请求无法完成,因为它与某些已经建立的规则相冲突。例如,如果您尝试将比现有文件更旧的文件上传到 Web 服务器,您可能会收到 409 错误 - 导致版本控制冲突。

Someone on a similar question right here on stackoverflow, said the answer was:

有人在stackoverflow上有一个类似的问题,他说答案是:

I've had this issue when I was referencing the url of the document library and not the destination file itself.

i.e. try http://server name/document library name/new file name.doc

当我引用文档库的 url 而不是目标文件本身时,我遇到了这个问题。

即尝试 http://server name/document library name/new file name.doc

However I am 100% sure this was not my case, since I checked the WebRequest's URI property several times and the URI was complete with filename, and all the folders in the path existed on the sharepoint site.

但是我 100% 确定这不是我的情况,因为我多次检查了 WebRequest 的 URI 属性并且 URI 是完整的文件名,并且路径中的所有文件夹都存在于 sharepoint 站点上。

Anyways, I hope this helps someone.

无论如何,我希望这对某人有所帮助。

回答by sk1900

I found 2 things worth mentioning while uploading files using webdav and http web request. First, for the provider I was using, I had to append the filename at the end of the provider url. Ihad to append the port number in the url. And I also set the Request method to PUT instead of POST.

在使用 webdav 和 http web 请求上传文件时,我发现有两件事值得一提。首先,对于我使用的提供程序,我必须在提供程序 url 的末尾附加文件名。我必须在 url 中附加端口号。我还将请求方法设置为 PUT 而不是 POST。

example:

例子:

string webdavUrl = "https://localhost:443/downloads/test.pdf";
request.Method = "PUT";

回答by Shravan Jain

We are also getting the same error while we are trying to access a same resource with in milliseconds. Like if i try to POSTsome data to www.abc.com/blogand with in milliseconds an other request will also go for the same resource i.e. www.abc.com/blogfrom the same user. So it'll give the 409error.

当我们试图以毫秒为单位访问相同的资源时,我们也遇到了同样的错误。就像如果我尝试以毫秒为单位发送POST一些数据,www.abc.com/blog另一个请求也将请求相同的资源,即www.abc.com/blog来自同一用户。所以它会给出409错误。

回答by VinPro

I encountered similar issue when uploading a file returned 409.

我在上传返回 409 的文件时遇到了类似的问题。

Besides issues mentioned above it can also happen due to file size restrictions for POST on the server side. For example, tomcat (java web server) have POST size limit of 2MBby default.

除了上面提到的问题,它也可能由于服务器端 POST 的文件大小限制而发生。例如,tomcat(java web 服务器)默认有 2MBPOST 大小限制

回答by user3563159

回答by abdullah imran

Its because of wrong path provided. It may be that the url contains space and if the case url has to be properly constructed.

这是因为提供了错误的路径。可能是 url 包含空格,并且 case url 必须正确构造。

The correct url should be in the format with file name included like "http://servername/document library name/new file name"

正确的 url 应该是包含文件名的格式,如“ http://服务器名称/文档库名称/新文件名”

So if report.xlsx is the file that has to be uploaded at "http://servername/Team/Dev Team" then path comes out to be is "http://servername/Team/Dev Team/report.xlsx". It contains space so it should be reconstructed as "http://servername/Team/Dev%20Team/report.xlsx" and should be used.

因此,如果 report.xlsx 是必须上传到“ http://servername/Team/Dev Team”的文件,那么路径就会是“ http://servername/Team/Dev Team/report.xlsx ”。它包含空间,因此应将其重构为“ http://servername/Team/Dev%20Team/report.xlsx”并应使用。

回答by Daniel Nyamasyo

I is because you are using predefined variables to naming your filename. change your filename from e.g register.asp to registerUser.asp. That will solve your issue

我是因为您正在使用预定义的变量来命名您的文件名。将您的文件名从例如 register.asp 更改为 registerUser.asp。这将解决您的问题