I'm running the following line in curl trying to setup couchdb replication:
curl -X POST -d '{"source":"http://user:p开发者_开发百科assword@siteA.com:5984/main","target":"main"}' -H 'Content-Type: application/json' http://user:password@siteB.com/_replicate
It keeps returning the following error:
{"error":"bad_request","reason":"invalid UTF-8 JSON"}
As far as I can tell the JSON seems valid. Any ideas?
I'm also using Powershell as well.
It happend many times to me as well. PowerShell parser (who knows why) removes quotes in the json.
So it sends it to curl like '{source:http://user:password@siteA.com:5984/main,target:main}' You need to call it like this:
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
Look at http://pscx.codeplex.com/ module. EchoArgs
might help when discovering such problems.
Looking at the CouchDB wiki I found this which could be useful to solve your issue. Basically under Windows you need to escape special characters or to write the JSON in a file and use that from the curl CLI.
I've had problems with curl and PowerShell before - my resolution was to call it from a batch file (the output put into a PowerShell variable)... thought it might be related to the way arguments were passed to curl being misinterpreted - I never got to the bottom of it as this worked...
maybe this could help http://huddledmasses.org/the-problem-with-calling-legacy-or-native-apps-from-powershell/
In order not to write all the json part manually, as you use powershell, you should try PSCouchDB.
Replicas as well:
PS >using module PSCouchDB
PS >$rep = New-Object PSCouchDBReplication -ArgumentList 'main','main_rep'
PS >$rep.SetContinuous()
PS >New-CouchDBReplication -Data $rep -Authorization "admin:password"
reference: https://pscouchdb.readthedocs.io/en/latest/server.html#create-replica
精彩评论