从 C# 代码更新文档 ID 中哈希斜杠的 CouchDB 文档
我已经使用文档 ID 中包含斜杠 (/) 的文档创建了 CouchDB 数据库。 我正在尝试从 C# 代码更新数据库,我尝试了几个 CouchDB 库,还使用了普通的旧 HttpWebRequest 类,但我全部失败,因为 .NET Uri 类转义了传递给它的字符串。 我需要创建一个像这样的 Uri:
http://myserver.com/db/firstpart%2Fsecondpart
它将始终被 .NET Uri 类转义为
http://myserver.com/db/firstpart/secondpart
这导致 CouchDB 将文档内容视为 ID 为firstpart 的文档的附件,而不是将文档视为 ID 为firstpart/secondpart 的文档的内容。
有什么想法吗?
I have create CouchDB database with documents that have slash (/) in the document ID.
I'm trying to update the database from C# code, I've try several CouchDB libs and also using plain-old-HttpWebRequest class but I fail with all because .NET Uri class escape the string pass into it.
I need to create a Uri like so:
http://myserver.com/db/firstpart%2Fsecondpart
which will always be escaped by .NET Uri class to
http://myserver.com/db/firstpart/secondpart
This cause CouchDB to treat the document content as attachment of document with ID firstpart instead of treat the document as content for document with id firstpart/secondpart.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想知道您是否可以对
%2f
部分本身进行编码,以便 .Net 对其解码一次,然后将正确编码的版本发送到服务器?%
字符编码为%25
,因此请尝试以下 URL:如果确实有效,也许您可以通过调用 System.Web.HttpUtility.UrlEncode。
更好的解决方案是检查 API 以禁用取消转义。对我来说,这感觉像是一个 API 错误。如果我告诉框架
one/two%2f Three
那么是什么赋予它二次猜测我的权利?但这就是 HTTP 的世界。 (我听说 Apache httpd 反向代理是一场噩梦。)I wonder if you could encode the
%2f
part itself, so that .Net will decode it once, and then send the correctly-encoded version to the server?The
%
character encodes as%25
, therefore try this URL:If that does work, maybe you could improve the code by calling System.Web.HttpUtility.UrlEncode.
A better solution would be to check the API to disable un-escaping. That feels like an API bug to me. If I tell the framework
one/two%2fthree
then what gives it the right to second-guess me? But that is the world of HTTP. (I hear that Apache httpd reverse-proxies are a nightmare with this.)