일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- Windows
- context
- find
- resource
- JavaScript
- bash
- tomcat
- grep
- 네트워크
- 단축키
- VirtualBox
- plugin
- lsof
- profile
- import
- Eclipse
- ssh
- maVen
- web.xml
- Quartz
- netsh
- 줄바꿈 문자
- Mac
- Windows 10
- GIT
- IntelliJ
- Source
- vscode
- port
- xargs
- 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 |