import java.net.Authenticator; import java.net.PasswordAuthentication; public class fanfouauth extends Authenticator { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("用户名","密码".toCharArray()); } }  

 

使用时 以饭否的API为例,每一次在使用URL的时候,调用Authenticator.setDefault一下.就可以了~

Authenticator.setDefault(new fanfouauth()); URL url = new URL("http://api.fanfou.com/account/verify_credentials.json"); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); StringBuffer sb = new StringBuffer(""); String str=""; while((str = reader.readLine())!= null) sb.append(str); return sb.toString(); 

 

更多相关文章

  1. android、webService 天气预报demo
  2. OKhttp上传头像,调用相机相册进行裁剪
  3. Android调用邮件客户端
  4. Android(安卓)打开资源raw文件
  5. 模拟按键操作的几种方式
  6. 解析#android.view.InflateException#
  7. android 登录界面 记住多组账号与密码
  8. 【备忘】Android模拟小球自由落体(SurfaceView)
  9. RxJava2源码分析

随机推荐

  1. Android(安卓)利用setpixels设置单色位图
  2. Android studio配置NDK问题小结
  3. Android - How to mount NFS in emulator
  4. Android面试题目(10) 内存泄露
  5. android ScrollView嵌套RecyclerView只显
  6. gentoo 制作android image
  7. Android客户端Socket连接PC服务器端(加评
  8. Android 更改程序icon图标
  9. fs/binfmt_aout.c:270: error: 'SEGMENT_
  10. unity3d IL2CPP for android