Settings
|
Sign in
|
Sign up
Bar
Post
Home
>
Bar 安卓 (程序開發)
>
View post
Reply the post
|
View all
The author has
2
posts.
[資料]HttpPost設置用戶登錄信息(HTTP 401)(HTTP Authentication)
Floor 1
巨大八爪鱼
5/1/15 0:35
HttpPost httpPost = new HttpPost(URL);
String account = "用戶名:密碼";
String auth = "Basic " + Base64.encodeToString(account.getBytes(), Base64.NO_WRAP);
httpPost.setHeader("Authorization", auth);
Floor 2
巨大八爪鱼
5/1/15 0:37
其中Base64.NO_WRAP非常關鍵,不能改成Base64.DEFAULT,否則就會出現HTTP 400錯誤,也就是服務器無法理解HTTP請求。
另外,順便一提,PHP中的Base64編碼是這樣進行的:
<?php
$str = '用戶名:密碼';
echo base64_encode($str);
?>
Content converter:
No conversion
Mainland
Taiwan
Hong Kong
Singapore
Reply the post
Content:
User:
You are currently anonymous.
Captcha:
Unclear? Try another one.