3
我曾經在終端中使用curl命令來訪問php網頁,以測試網頁中的一些API。它工作正常。如何使用curl命令行通過HTTP基本認證來訪問網頁
例如:
curl www.somesite.com -d parmetername=value
現在這個頁面有基本的HTTP認證。我知道我只需要添加-u來提供用戶名和密碼。我也是一派,幾乎每個人都建議做同樣如下:
curl -u username:password www.somesite.com -d parmetername=value
curl --user username:password www.somesite.com -d parmetername=value
或
curl http://username:[email protected] -d parmetername=value
我曾嘗試他們兩個,他們沒有工作。我得到了如下相同的錯誤信息:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
<p>Additionally, a 401 Authorization Required
error was encountered while trying to use an ErrorDocument to handle the request.</p>
<hr>
<address>Apache/2.2.29 (Unix) mod_ssl/2.2.29 OpenSSL/1.0.1e-fips mod_bwlimited/1.4 Server at www.somesite.com Port 80</address>
</body></html>
我試圖通過瀏覽器訪問網站。在提示窗口中輸入用戶名和密碼後。我可以訪問這個網站。
有人知道這裏發生了什麼嗎? 謝謝。
請重新檢查在URL的用戶名和密碼,你嘗試,因爲這是爲我工作(個人服務器上)。 – watery
可能重複的http://stackoverflow.com/questions/3044315/how-to-set-the-authorization-header-using-curl – Jan
我試了幾次,並在不同的計算機上......不工作......我是思考如果這必須做一些與服務器設置... – user3293338