java.io.IOException: Server returned HTTP response code: 415 for URL

URL url = new URL(address);
URL url = new URL(address);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setConnectTimeout(20000);
connection.setReadTimeout(300000);
connection.setRequestProperty("Charset", "UTF-8");
OutputStream os = connection.getOutputStream();

os.write(sb.toString().getBytes());
os.close();
				
is = connection.getInputStream();
					

解决方案:加入红色部分即可

猜你喜欢

转载自freegaga.iteye.com/blog/1671673