Android的基本身份验证2.2+ [英] Android Basic Authentication 2.2+
问题描述
您好,
我与基本HTTP认证struggeling像我见过很多人..
I am struggeling with Basic HTTP Authentication like I have seen many others..
public String getJSONObject()
{
try
{
String strURL = "deleted_manually_here";
StringBuilder result = new StringBuilder();
String base64EncodedCredentials = Base64.encodeToString(
(username+":"+password).getBytes(), Base64.DEFAULT);
HttpPost post = new HttpPost(strURL);
post.addHeader("Authorization", "Basic " + base64EncodedCredentials);
ResponseHandler<String> responseHandler=new BasicResponseHandler();
String responseBody=client.execute(post, responseHandler);
JSONObject response=new JSONObject(responseBody);
Log.d(TAG,"SUCCESS!");
return "B";
}
catch (Throwable t) {
Log.e(TAG, "EXCEPTION in updateStatus()", t);
return "N";
}
}
如果用户名和放大器;密码是一个私人最终字符串。
Where username & password is a private final String.
但在我的亚行logcat我得到:
But in my adb logcat I get:
E / GetHttpQuotes(392):例外updateStatus()&LT;&LT;我的日志文本
E / GetHttpQuotes(392):java.net.SocketException异常:权限被拒绝&LT;&LT;那么什么是错的。
E/GetHttpQuotes( 392): EXCEPTION in updateStatus() << my log text" E/GetHttpQuotes( 392): java.net.SocketException: Permission denied << so something is wrong..
我试过很多code,我发现,但没有工作...
I tried so many code I found but nothing worked...
推荐答案
解决这个问题是pretty简单!
The solution to this problem is pretty simple!
互联网权限的Android清单失踪是pretty根本首先在这类问题进行检查。
The Internet Permission in the Android Manifest was missing which is pretty fundamental to check in problems like these at first.
的http://developer.android.com/reference/android/Manifest.permission.html#INTERNET
这篇关于Android的基本身份验证2.2+的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!