인증이 필요한 웹 캐스트 Socialcast에서 컨텐츠를 가져 오려고합니다. (먼저 기본 인증이있는 HTTP 게시를 수행 한 다음 HTTP GET을 시도합니다.) 이
[email protected] : 데모 Base64로 인코딩 된 인증 문자열 : ZW1pbHlAc29jaWFsY2FzdC5jb206ZGVtbw의 == * 당신은 redirected되고있다 을 BEGIN 은 내가 "결과"로이 수신 몇 가지 코드를 시도했다. HTTP 기본 인증 Java
가 여기에 HTTP 기본 인증을위한 코드 * END : 나는 나중에는 GET을 수행하려고 할 때
try {
String webPage = "http://demo.socialcast.com";
String name = "[email protected]";
String password = "demo";
String authString = name + ":" + password;
System.out.println("auth string: " + authString);
byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
String authStringEnc = new String(authEncBytes);
System.out.println("Base64 encoded auth string: " + authStringEnc);
URL url = new URL(webPage);
URLConnection urlConnection = url.openConnection();
urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
InputStream is = urlConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
int numCharsRead;
char[] charArray = new char[1024];
StringBuffer sb = new StringBuffer();
while ((numCharsRead = isr.read(charArray)) > 0) {
sb.append(charArray, 0, numCharsRead);
}
String result = sb.toString();
System.out.println("*** BEGIN ***");
System.out.println(result);
System.out.println("*** END ***");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
은 그러나, 무단 말한다. 자격 증명은 [email protected]/demo입니다. 즉, 나 자신의 Socialcast 인스턴스에 액세스 할 수 없기 때문에 Socialcast Dev가 제공합니다.
이 코드가 잘못 되었습니까? 어떻게 제대로 할 수 있습니까? BTW, 나는 HttpClient 4.x를 사용하고있다.
예. 하지만 첫 번째 경우에도 작동하지 않습니다 ... –
HTTPS 페이지로 리디렉션 된 것 같습니다. 직접 쿼리를 시도 했습니까? –
좋은 힌트, 나는 시도 할 것이다! –