Skip to content

Instantly share code, notes, and snippets.

@PyYoshi
Created November 8, 2011 18:26
Show Gist options
  • Select an option

  • Save PyYoshi/1348632 to your computer and use it in GitHub Desktop.

Select an option

Save PyYoshi/1348632 to your computer and use it in GitHub Desktop.
BasicAuthのサンプル
public class BasicAuth{
private String auth_type = "BASIC";
private String login_uri = "http://www.tumblr.com/api/authenticate";
private String username;
private String passwd;
BasicAuth(String email, String password){
this.username = email;
this.passwd = password;
}
/**
* リクエストヘッダにauth用ヘッダを付加して返す
* @param HttpURLConnection request;
*
*/
public final HttpURLConnection sign(HttpURLConnection request){
// authヘッダの付加
String basic = this.username + ":" + this.passwd;
basic = new String(basic.getBytes());
request.setRequestProperty(
"Authorization",
"Basic "+basic
);
return request;
}
public final void getUserInfo(){
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment