Android HTTP Authentication

无人久伴 提交于 2019-12-12 18:05:21

问题


How do I authenticate via HTTP in Android?


回答1:


I face very much dificuly to authenticate via HTTP in Android as in browser (web and Android native) it worked perfect and ask for credentials but this scene is not in code. so here is the code I used.

URL url = new URL("YOUR URL HERE");


Authenticator.setDefault(new Authenticator(){
          @Override
          protected PasswordAuthentication getPasswordAuthentication() {
                 System.err.println("Feeding username and password for " + getRequestingScheme());
                 return (new PasswordAuthentication("username", "password".toCharArray()));
          }});
InputStream stream = url.openStream();


来源:https://stackoverflow.com/questions/7288526/android-http-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!