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