使用我的应用程序连接到 php .htaccess
Connect to php .htaccess with my application
我通过 .htaccess 文件锁定了 php 页面(用户名和密码)。
我尝试使用我的 android 应用程序连接到此 php。
我在这里试试这个页面:Connect to php page using .htaccess with android application
但是不行..
我的代码:
HttpClient cnxHttp = new DefaultHttpClient();
HttpPost paramCnx = new HttpPost(strings[0]);
paramCnx.setHeader("Authorization", "Basic " + new Base64().encodeToString("user:mdp".getBytes("UTF-8"), Base64.DEFAULT));
我收到 getBytes 错误:UnsupportedEncodingException。
我不明白为什么,somoene可以给我解释一下并给我正确的代码吗?
我找到了。
答案:
String authorizationString = "Basic " + Base64.encodeToString(
("your_login" + ":" + "your_password").getBytes(),
Base64.NO_WRAP); //Base64.NO_WRAP flag
post.setHeader("Authorization", authorizationString);
我通过 .htaccess 文件锁定了 php 页面(用户名和密码)。 我尝试使用我的 android 应用程序连接到此 php。
我在这里试试这个页面:Connect to php page using .htaccess with android application
但是不行..
我的代码:
HttpClient cnxHttp = new DefaultHttpClient();
HttpPost paramCnx = new HttpPost(strings[0]);
paramCnx.setHeader("Authorization", "Basic " + new Base64().encodeToString("user:mdp".getBytes("UTF-8"), Base64.DEFAULT));
我收到 getBytes 错误:UnsupportedEncodingException。 我不明白为什么,somoene可以给我解释一下并给我正确的代码吗?
我找到了。 答案:
String authorizationString = "Basic " + Base64.encodeToString(
("your_login" + ":" + "your_password").getBytes(),
Base64.NO_WRAP); //Base64.NO_WRAP flag
post.setHeader("Authorization", authorizationString);