全て。
PHP Web ページ (http://www.agroclimate.org/howard/GDD/getFAWNDailyData.php?loc=490&frommonth=6&fromday=26&fromyear=2009&tomonth=7&today=7&toyear=2009) から気象データを取得するための Java コードをテストしています。 )。
私のコードは私のコンピューター (win7、jre6、および jre7) でうまく動作します。Web ブラウザー (explorer9、chrome) で上記のリンクにアクセスすると、ブラウザーは「getFAWNDailyData.php」ページ自体をダウンロードし、実行しません。
私の問題は、コードが同様の仕様 (win7、jre6、および jre7) の他のコンピューターでは機能しなかったことです。コードは、ページによって生成されたデータではなく、php ページのソース自体を読み取ろうとしました。そして、その Web ブラウザー (explorer9、chrome) も、私のようにページ自体をダウンロードします。
2 台のコンピューターに違いは見られず、他のコンピューターではエラーを生成できませんでした。
私がチェックできる手がかりを教えていただけますか?
これが私のコードです。
try {
url = new URL(
"http://www.agroclimate.org/howard/GDD/getFAWNDailyData.php?loc=490&frommonth=6&fromday=26&fromyear=2009&tomonth=7&today=7&toyear=2009");
URLConnection urlConn = url.openConnection();
InputStream is = urlConn.getInputStream();
InputStreamReader reader = new InputStreamReader(is);
BufferedReader bf = new BufferedReader(reader);
int lines = 0;
int wind_count = 0, airtemp_count = 0;
// et starts from the 2nd line
String firstLine = bf.readLine(); // firstLine is "DATETIME,ET"
System.out.print("\n" + "-----" + firstLine + "\n");
String year = "", month = "", day = "", WindCount = "", AirTempCount = "";
int monthNum = 0;
String line = bf.readLine();
System.out.print("\n" + "-----" + line + "\n");
StringTokenizer st = new StringTokenizer(line, ",");
if (st.hasMoreTokens()) {
year = st.nextToken();
}
if (st.hasMoreTokens()) {
month = st.nextToken();
String[] values = month.split(" ");
day = values[0].substring(1);
year = values[2].replace('"', ' ');
year = year.trim();
month = values[1].trim();
monthNum = getMonthValue(month);
}
System.out.println("year---:[" + year + "]");
System.out.println("month---:[" + month + "]");
System.out.println("day---:[" + day + "]");
} catch (MalformedURLException me) {
me.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null)
try {
is.close();
} catch (IOException e) {
;
}
}
ありがとう。