2013-04-09 2 views
1

URL에 https 연결을 시도하고 있습니다. 이미 예외 : 이미 연결됨, HttpsUrlConnection

를 연결 우리가 자바를 통해 보안 연결을 만들려면 어떻게해야 확실하지 않다 :이 예외를

예외를 얻고있다. 아무도 이것으로 나를 도울 수 있습니까?

여기 내 코드입니다.

public static String getCon() { 
    String result="",cookie=""; 
    System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); 
    java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); 
try { 
URL url= new URL("https://jazz.net/"); 
HttpsURLConnection connection= (HttpsURLConnection) url.openConnection(); 
String cookieHeader = connection.getHeaderField("set-cookie"); 
if (cookieHeader != null) { 
    int index = cookieHeader.indexOf(";"); 
    if (index >= 0) 
     cookie = cookieHeader.substring(0, index); 
    connection.setRequestProperty("Cookie", cookie); 
}connection.setDoInput(true); 
connection.setDoOutput(true); 
connection.setRequestMethod("POST"); 
connection.setFollowRedirects(false); 

connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); 
connection.setRequestProperty("Accept", "application/xml"); 
connection.setRequestProperty("User-Agent", "yes"); 
DataInputStream input = new DataInputStream(connection.getInputStream()); 

StringBuffer buf= new StringBuffer(); 
// read in each character until end-of-stream is detected 
for(int c = input.read(); c != -1; c = input.read()) 
    buf.append(c); 
input.close(); 
result=buf.toString(); 
} catch (Exception e) { 
// TODO Auto-generated catch block 
return result+" exception "+e.getMessage(); 
} 


    return result; 
} 
+1

전체 스택 추적을 게시하고이 문제가 발생한 코드의 줄 번호를 언급하십시오. 연결이 이미 설정된 경우 어딘가에 연결 속성을 설정하고 있습니다. –

답변

0

연결하기 전에 Set-Cookie 헤더가 표시됩니다. 의미가 없습니다. 요청에서 해당 헤더 집합을 원하면 설정하십시오. getHeader()는 응답에서 헤더를 가져옵니다.

관련 문제