如何定义正确使用卷曲基本的HTTP验证? [英] How to define the basic HTTP authentication using cURL correctly?

查看:284
本文介绍了如何定义正确使用卷曲基本的HTTP验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习Apigility( Apigility实况 - > REST服务教程),并试图通过卷曲发基本身份验证的POST请求:

  $卷曲-X POST -i -H内容类型:应用程序/ HAL + JSON-H授权:基本YXBpdXNlcjphcGlwd2Q =HTTP://apigilityhw.sandbox.loc /状态

YXBpdXNlcjphcGlwd2Q = 是基带64 codeD字符串我的凭据 apiuser:apipwd 。凭据保存在 /数据/ htpasswd的 apiuser:$ apr1 $ 3J4cyqEw $ WKga3rQMkxvnevMuBaekg / )。

看起来是这样的:

  HTTP / 1.1 401未经授权
服务器:nginx / 1.4.7
日期:星期一,2014年9月22日7时48分47秒GMT
内容类型:应用程序/问题+ JSON
传输编码:分块
连接:保持活动
的X已启动方式:PHP / 5.5.12-1〜dotdeb.1
WWW身份验证:基本境界=API

在哪儿错在这里?如何得到它的工作?


解决方案

 卷曲-u用户名:密码的http://
卷曲-u用户名的http://

从文档页面:


  

-u,--user<使用者:密码>


  
  

指定的用户名和密码,用于服务器身份验证。
  覆盖-n,--netrc和--netrc选。


  
  

如果你只是指定的用户名,袅袅会提示输入密码。


  
  

的用户名和密码分裂在第一结肠,这
  使其无法在用户名称中使用冒号使用此选项。
  密码可以,仍。


  
  

在使用Kerberos V5与基于Windows的服务器,你应该包括
  Windows域名中的用户名中,为了使服务器
  成功地获得Kerberos票据。如果你不那么初始
  验证握手会失败。


  
  

当使用NTLM,用户名可以简单地指定为用户
  名,不域,如果有一个单域和森林中
  您的设置,例如


  
  

要指定域名或者使用低级别登录名或UPN
  (用户主体名称)格式。例如,实施例\\用户和
  user@example.com分别。


  
  

如果您使用的是启用SSPI-卷曲的Windows二进制和执行Kerberos V5,
  协商,NTLM或摘要式身份验证,那么你可以告诉卷曲
  通过指定选择环境中的用户名和密码
  一个冒号使用此选项:-u:


  
  

如果使用此选项好几次,最后一个将被使用。


http://curl.haxx.se/docs/manpage.html#-u

请注意,你并不需要 - 基本 标志,因为它是默认的。

I'm learning Apigility (Apigility docu -> REST Service Tutorial) and trying to send a POST request with basic authentication via cURL:

$ curl -X POST -i -H "Content-Type: application/hal+json" -H "Authorization: Basic YXBpdXNlcjphcGlwd2Q=" http://apigilityhw.sandbox.loc/status

YXBpdXNlcjphcGlwd2Q= is the base 64 encoded string with my credentials apiuser:apipwd. The credentials are saved in the /data/htpasswd (apiuser:$apr1$3J4cyqEw$WKga3rQMkxvnevMuBaekg/).

The looks like this:

HTTP/1.1 401 Unauthorized
Server: nginx/1.4.7
Date: Mon, 22 Sep 2014 07:48:47 GMT
Content-Type: application/problem+json
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.5.12-1~dotdeb.1
WWW-Authenticate: Basic realm="api"

Where is the mistake here? How to get it work?

解决方案

curl -u username:password http://
curl -u username http://

From the documentation page:

-u, --user <user:password>

Specify the user name and password to use for server authentication. Overrides -n, --netrc and --netrc-optional.

If you simply specify the user name, curl will prompt for a password.

The user name and passwords are split up on the first colon, which makes it impossible to use a colon in the user name with this option. The password can, still.

When using Kerberos V5 with a Windows based server you should include the Windows domain name in the user name, in order for the server to succesfully obtain a Kerberos Ticket. If you don't then the initial authentication handshake may fail.

When using NTLM, the user name can be specified simply as the user name, without the domain, if there is a single domain and forest in your setup for example.

To specify the domain name use either Down-Level Logon Name or UPN (User Principal Name) formats. For example, EXAMPLE\user and user@example.com respectively.

If you use a Windows SSPI-enabled curl binary and perform Kerberos V5, Negotiate, NTLM or Digest authentication then you can tell curl to select the user name and password from your environment by specifying a single colon with this option: "-u :".

If this option is used several times, the last one will be used.

http://curl.haxx.se/docs/manpage.html#-u

Note that you do not need --basic flag as it is the default.

这篇关于如何定义正确使用卷曲基本的HTTP验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆