티스토리 뷰
IT/Error
java.io.FileNotFoundException: Response: '415: Unsupported Media Type' for url
Normal_One 2017. 12. 23. 11:00SOAP 통신 테스트 중에 제목과 같은 에러가 났습니다. 궁금해서 구글에서 찾아보니 연결하는 URL 측 서버쪽에서 받아들이지 않는 미디어 타입을 우리 측에서 보내서 발생하는 에러라고 합나다.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | public String soapDataTransfer() { try { URL url; /* * Weblogic에서 https url 사용하기 위한 방법 (new sun.net.www.protocol.https.Handler()) */ url = new URL("https://url.com"); /* * SOAP XML문 구성 */ String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + " soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" " + " xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" " + " xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\"> " + " <soap:Body> " + " <DATA>" + "DATA" + "</DATA> " + " </soap:Body> " + "</soap:Envelope> "; HttpURLConnection conn = (HttpURLConnection)url.openConnection(); /* * 연결 시간과 header 설정 */ conn.setConnectTimeout(3000); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.addRequestProperty("Content-Type", "text/xml"); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(xml); wr.flush(); InputStreamReader in = new InputStreamReader(conn.getInputStream(),"utf-8"); BufferedReader br = new BufferedReader(in); String strLine; String returnString = ""; /* * 보낸 XML에 대한 응답을 받아옴 */ while ((strLine = br.readLine()) != null){ returnString = returnString.concat(strLine); } in.close(); wr.close(); /* * 보낸 XML에 대한 응답을 출력. */ System.out.println(returnString); } catch (Exception e) { e.printStackTrace(); } return "soapDataTransfer"; } | cs |
위에 코드 중에서 conn.addRequestProperty("Content-Type", "text/xml"); 의 Content-Type을 바꾸어 주거나, 아니면 연결하는 URL의 서버에서 받아들이는 Content-Type을 바꾸어주면 됩니다. 저의 경우에는 "text/xml"을 "application/xml"로 변경해 주었습니다.
'IT > Error' 카테고리의 다른 글
Toad for Oracle - ORA-00911: 문자가 부적합합니다. (0) | 2017.03.26 |
---|---|
Ojdbc - Error querying database. Cause: java.lang.NullPointerException (0) | 2017.03.26 |
Eclipse - An internal error occurred during: "Initializing Java Tooling" (0) | 2017.03.26 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday