일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- netsh
- find
- Mac
- plugin
- 단축키
- Quartz
- Eclipse
- xargs
- tomcat
- maVen
- grep
- Source
- profile
- Windows
- web.xml
- VirtualBox
- resource
- JavaScript
- bash
- ssh
- context
- GIT
- 네트워크
- 줄바꿈 문자
- port
- lsof
- import
- vscode
- Windows 10
- IntelliJ
- Today
- Total
develog
[Java] http 인증 접속 본문
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import org.apache.commons.codec.binary.Base64;
public class TestMain {
public static void main(String[] args) throws Exception {
BufferedReader br = null;
try {
String idpw = "username:password";
String encodedIdPw = new String(Base64.encodeBase64(idpw.getBytes()));
URL url = new URL("http://127.0.0.1/");
URLConnection urlConn = url.openConnection();
urlConn.setRequestProperty("Authorization", "Basic " + encodedIdPw);
urlConn.connect();
br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} finally {
if (br != null) {
br.close();
}
}
}
}
'Dev > Java' 카테고리의 다른 글
[Java] Java IO (0) | 2014.09.22 |
---|---|
[Java] removeTag (0) | 2014.09.18 |
[Java] System.getProperties(), System.getProperty() (0) | 2014.09.15 |
memory (0) | 2014.09.10 |
eclipse.ini (0) | 2014.09.10 |