【发布时间】:2015-11-27 09:40:51
【问题描述】:
我的 Ubuntu 或 Runnable JAR 中有一个 cron 作业计划正在运行。
我在字符串 URL 上收到异常,但在我的 Windows 开发中它没问题。它无法解析正确的string url 请在下方查看
java.io.FileNotFoundException: http://www.carlolotti.com/enoteca-vini-valdostani/chardonnay-elevé-en-fut-de-chene-anselmet-2007-6s0jwecq.asp
这里是源代码:
HttpURLConnection conn;
URL obj = new URL(url);
conn = (HttpURLConnection) obj.openConnection();
// default is GET
conn.setRequestMethod("GET");
conn.setUseCaches(true);
// act like a browser
conn.setRequestProperty("User-Agent", USER_AGENT);
conn.setRequestProperty("Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
int responseCode = conn.getResponseCode();
if(debug)
System.out.println("\nSending 'GET' request to URL : " + url);
if(debug)
System.out.println("Response Code : " + responseCode);
try{
BufferedReader in =
new BufferedReader(new InputStreamReader(conn.getInputStream() , "UTF-8"));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
//inputLine=StringEscapeUtils.escapeHtml3(inputLine);
//if(inputLine.contains("Albari"))
// t=1;
response.append(inputLine);
if(csv)
response.append(lineRet);
}
in.close();
return response;
}catch(Exception e){
e.printStackTrace();
}
return null;
我怀疑我的 Ubuntu 在我的语言环境 LANG=en_GB.UTF-8 上的语言是否需要将其更改为 en_US.UTF-8?我不太确定,但这是我的第一次调查。
【问题讨论】:
-
看起来应该被解释为 UTF-8 的东西被解释为 ISO-8859-1。但是如果没有源代码和关于字符串来自何处的解释,将很难为您提供帮助。
-
你是对的。我添加了我的源代码。
-
这个错误发生在哪里? URL 字符串的来源是什么?
-
url来自哪里?正如@RealSkeptic 提到的,这是一个转换问题。在您发布的 URL 中,-elevé-实际上应该是-elevé-。 UTF8 编码的é的转换导致 ISO-8859-1 上的é。 -
它来自使用jsoup解析的网站解析。我想知道在我的窗户上没问题。这是一个字符串
标签: java ubuntu ubuntu-14.04 webclient htmlunit