2012-09-28 14 views
0

我正在使用「curl」來獲取需要用戶名和密碼的網頁。curl post問題:輸入密碼變爲空

對於一些網頁,我可以表達得到我想要的頁面類似

curl -u myusername:mypassword url -o output.html. 

但對於其他一些網頁,我無法得到我想要的頁面。

我試過上面提到的表達式,它看起來是用戶名和密碼沒有與請求一起發送。

我也嘗試過這樣的表達式

curl -d"login_username=myusername&login_password=mypassword&action=login&submit=Login" url -o output.html. 

用戶名發送,但密碼仍然是空的。

順便提一下,在用戶名爲&的密碼輸入框中有一個「領域:LDAP」。

有人知道發生了什麼嗎?提前致謝。

回答

0

假設一個網站使用HTTP基本認證,詳細模式和-v選項讓您確認是否發送認證請求。如果發送認證請求,您可以看到授權標題如下。

$ curl -v -u user:password http://foo.example.com/auth/ -o output.html 

* About to connect() to x.x.x.x port 3128 
* Trying x.x.x.x... connected 
* Connected to proxy.example.com (x.x.x.x) port 3128 
* Server auth using Basic with user 'user' 
> GET http://foo.example.com/auth/ HTTP/1.1 
> Authorization: Basic cm9vdDpSaW5nMjAXMA== 
-1

爲捲曲的用戶名密碼&的語法是:

user,password 

user:password 

所以最後:

curl -s -v -u myusername,mypassword url 
+0

如果你認爲俺們這很有用,你可以'upvote'它。你也可以通過點擊'checkmark'(將綠色)'接受'回覆,這樣,搜索stackoverflow網站的人就會知道這個問題很好回答。這就是如何計算器工作,謝謝;) –

+0

我試過你的方式,它總是要求密碼。但是,'curl -u myusername:mypassword url -o output.html'可以正常工作,但對於我提到的情況並不適用。 – shirley

+1

我在網上查了一下手冊。我確定它應該是'user:password',** not **'user,password',請參閱http://curl.haxx.se/docs/manual.html以供參考。 – shirley