2016-08-01 85 views
1

我正在關注使用其API的GitHub's tutorial。在我的Git bash命令提示符下,我輸入以下cURL不會使用GitHub API提示我輸入密碼

curl -i https://api.github.com/users/defunkt 

像它應該這樣,便會在JSON。然而,當我鍵入

curl -i -u your_username https://api.github.com/users/defunkt 

它只是打印出新的生產線,好像在等我完成命令或東西。我需要按CTRL C才能逃脫。我也嘗試過不同的變化,

curl -i -u "your_username" https://api.github.com/users/defunkt 
curl -i --user your_username https://api.github.com/users/defunkt 
curl -i --user "your_username" https://api.github.com/users/defunkt 
curl -i -user your_username https://api.github.com/users/defunkt 
curl -i -user "your_username" https://api.github.com/users/defunkt 

而且沒有任何工作。我究竟做錯了什麼?

回答

2
-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 successfully 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 
      [email protected] 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. 

所以我猜你可能有兩個選擇。一種是當你得到新的行時輸入密碼。另一種方法是在您的用戶名用冒號分隔後包含密碼。

+0

'curl -i -u USERNAME:PASSWORD https:// api ...'工作。謝謝。但是,爲什麼它不能以第一種方式工作呢? (只需輸入命令,然後密碼在新行上就不起作用)在命令中輸入密碼後,會在shell歷史記錄中留下密碼。 – amallard

+0

我不確定。在我的系統上,達爾文內核版本15.2.0,我被提示輸入密碼。我可以建議查看手冊頁。人從你的終端捲曲。 – Imposter

相關問題