Java-读取PHP网页生成的数据时出错
全部 我正在测试从PHP网页获取天气数据的java代码(http://www.agroclimate.org/howard/GDD/getFAWNDailyData.php?loc=490&frommonth=6&fromday=26&fromyear=2009&tomonth=7&today=7&toyear=2009). 我的代码在我的计算机(win7、jre6和jre7)上运行良好。 当我在web浏览器(explorer9,chrome)中访问上述链接时,浏览器会下载“getFAWNDailyData.php”页面本身,而不是运行它 我的问题是,该代码在其他具有类似规范(win7、jre6和jre7)的计算机上不起作用。代码试图读取php页面源代码本身,而不是页面生成的数据。而且,它的网络浏览器(explorer9、chrome)也像我一样下载网页本身 我无法在两台计算机之间找到任何差异,也无法在其他计算机上生成错误 你能给我一些线索让我查一下吗 这是我的密码Java-读取PHP网页生成的数据时出错,java,php,urlconnection,Java,Php,Urlconnection,全部 我正在测试从PHP网页获取天气数据的java代码(http://www.agroclimate.org/howard/GDD/getFAWNDailyData.php?loc=490&frommonth=6&fromday=26&fromyear=2009&tomonth=7&today=7&toyear=2009). 我的代码在我的计算机(win7、jre6和jre7)上运行良好。 当我在web浏览器(explorer9,chrome)中访问上述链接时,浏览器会下载“getFAWNDa
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) {
;
}
}
谢谢。您所说的“代码试图读取php页面源代码本身,而不是页面生成的数据”是什么意思?错误/输出/等等是什么样子的?php代码是下载的,而不是php页面生成的数据。年度输出是php代码的第二行,如下所示;URL已经死了,所以问题也来了。算法很难看,没有上下文很难说