CURL CouchDB复制命令-无效的JSON

4

我正在使用curl运行以下代码,尝试设置couchdb的复制:

curl -X POST -d '{"source":"http://user:password@siteA.com:5984/main","target":"main"}' -H 'Content-Type: application/json' http://user:password@siteB.com/_replicate

它一直返回以下错误:
{"error":"bad_request","reason":"invalid UTF-8 JSON"}

据我所知,JSON看起来是有效的。有什么想法吗? 我也正在使用PowerShell。

一个旁注。在你的例子中,看起来你把目标作为源传递,把源作为目标传递了。 - Cinquo
4个回答

7

我也遇到过很多次这种情况。PowerShell解析器(谁知道为什么)会在JSON中删除引号。

因此,它将其发送给curl,就像'{source:http://user:password@siteA.com:5984/main,target:main}'一样。 您需要这样调用它:

curl -X POST -d '{"""source""":"""http://user:password@siteA.com:5984/main""","""target""":"""main"""}' -H 'Content-Type: application/json' http://user:password@siteB.com/_replicate

请查看http://pscx.codeplex.com/模块。当发现这些问题时,EchoArgs可能会有所帮助。


2

浏览CouchDB wiki,我发现这个可能对解决您的问题有用。基本上,在Windows下,您需要转义特殊字符或将JSON写入文件并从curl CLI使用。


0

0
为了不手动编写所有的json部分,当您使用PowerShell时,您应该尝试PSCouchDB
还有副本:
PS >using module PSCouchDB
PS >$rep = New-Object PSCouchDBReplication -ArgumentList 'main','main_rep'
PS >$rep.SetContinuous()
PS >New-CouchDBReplication -Data $rep -Authorization "admin:password"

参考文献:https://pscouchdb.readthedocs.io/en/latest/server.html#create-replica


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接