需要发送带有西里尔字符的http请求。 在字符串“文本”中我有一个俄语单词。它编码了最终地址,但connection.getInputStream()抛出异常。用英语单词,它可以正常工作。编码的URL(地址)通常在浏览器中打开。 这是一个代码:
String text = params[0] ;
try {
text = URLEncoder.encode(text, HTTP.UTF_8) ;
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace() ;
}
String address = "http://"+text+".jpg.to" ;
String result = "" ;
BufferedReader reader = null ;
try {
URL url = new URL(address) ;
URLConnection connection = url.openConnection() ;
InputStream stream = connection.getInputStream() ;
InputStreamReader inReader = new InputStreamReader(stream, "UTF-8") ;
reader = new BufferedReader(inReader) ;
String inputLine = null ;
while ((inputLine = reader.readLine()) != null) {
result = result+inputLine ;
}
} catch (Exception e) {
e.printStackTrace() ;
} finally {
try {
reader.close() ;
} catch (Exception e) {
e.printStackTrace() ;
}
}