无法访问CouchDB实例:返回401 Unauthorized(Can't access CouchDB instance: returns 401 Unauthorized)

编程入门 行业动态 更新时间:2024-10-28 15:22:47
无法访问CouchDB实例:返回401 Unauthorized(Can't access CouchDB instance: returns 401 Unauthorized)

我无法使用curl或任何第三方CouchDB客户端库访问我的couchdb实例。

它返回:401未经授权!

我正在使用网址

https://instance.smileupps.com/

使用curl这是我输入的命令行:

curl https://instance.smileupps.com/

I can't access my couchdb instance it using curl or any third party CouchDB client library..

It returns: 401 Unauthorized!

I am using the url

https://instance.smileupps.com/

Using curl this is the command line I entered:

curl https://instance.smileupps.com/

最满意答案

“401 Unauthorized”表示您的实例不在管理员方 (您已经指定了至少一个管理员凭据对)。

在这种情况下, 您应该发送经过身份验证的请求 ,包括curl或任何第三方客户端库。

1)简单的方法( 不适用于带有特殊字符的凭证

您可以通过在主机名前加上username:password来使用修改后的URL,如:

https://my_username:my_password@instance.smileupps.com

这几乎总是很好..

2)简单但安全的方式更可靠,更安全

如果1)不起作用,可能是您在用户名或密码中使用特殊字符,curl或couchdb库在发送请求之前无法正确解析URL。

在这种情况下,您可以通过发送http基本授权标头执行身份验证...这是一个标题,如:

授权:基本bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ =

其中“bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ =”是“my_username:my_password”的base64_encode。 您可以使用base64在线编码器服务对您自己的凭据进行编码。

所以curl命令行会变成

> curl -v -H "Authorization: Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=" -H > "Content-type:application/json" -X GET > https://instance.smileupps.com/mydatabasename

如果您使用的是第三方库 ,则应在其文档中找到添加自定义标头的方法,并添加以下内容:

授权:基本bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ =

"401 Unauthorized" means that your instance is not in admin party (you have already specified at least one administrator credentials pair).

In this case you should send an authenticated request, both with curl or with any third party client side library.

1) THE EASY WAY (doesn't work with credentials with special characters)

You can use a modified url by prefixing the hostname with username:password like:

https://my_username:my_password@instance.smileupps.com

This works fine almost always..

2) THE TRICKY BUT SAFER WAY (More reliable and safer)

If 1) does not work, probably you are using special characters within your username or password, and curl or the couchdb library cannot correctly parse the url before sending the request.

In this case you can perform authentication by sending the http basic authorization header... that is a header like:

Authorization: Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=

where "bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=" is the base64_encode of "my_username:my_password". You can use the base64 online encoder service to encode your own credentials.

So the curl command line would become something like:

> curl -v -H "Authorization: Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=" -H > "Content-type:application/json" -X GET > https://instance.smileupps.com/mydatabasename

If you are using a third party library instead, you should find in its documentation the way to add a custom header, and add the following:

Authorization: Basic bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=

更多推荐

curl,instance,https,使用,电脑培训,计算机培训,IT培训"/> <meta name="descri

本文发布于:2023-07-14 20:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1107180.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实例   无法访问   CouchDB   returns   instance

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!