解决Java URL Http 505错误的方法
解决Java URL Http 505错误的方法
public static void getDataBySendingURL2(String theURL){
final String FOUND_BEGIN = "wmsxml==";
String xmlContent="";
try {
URL url = new URL(theURL);
System.out.println(url);
InputStream input = url.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(input));
String strLine, strData = "";
while((strLine= br.readLine())!=null){
strData = strData + strLine;
}
String array[] = strData.split("!!");
for(int i=0;i<array.length;i++){
if(array[i].indexOf(FOUND_BEGIN)>=0){
xmlContent=array[i].substring(FOUND_BEGIN.length());
break;
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(xmlContent);
}
当传入的String theURL中含有空格时,这句话:
InputStream input = url.openStream();
会报Http 505错误
解决办法是去掉空格改成%20
但为什么会报505的错误呢(Version Not supported)?