我通过.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可以向我解释并提供正确的代码吗?
答案 0 :(得分:0)
我找到了。 答案:
String authorizationString = "Basic " + Base64.encodeToString(
("your_login" + ":" + "your_password").getBytes(),
Base64.NO_WRAP); //Base64.NO_WRAP flag
post.setHeader("Authorization", authorizationString);