前几天自己跑的例子还好好的。今天一拿来用。发现这么个奇怪的问题。代码如下
URL url = new URL(uriPath);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(5 * 1000);
//conn.setRequestProperty("Accept", "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
conn.setRequestProperty("Accept-Language", "zh-CN");
conn.setRequestProperty("Charset", "UTF-8");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
//要是不设置为post的话。就会在手机上面(不是模拟器)出现connection reset 之类的错误!
conn.setRequestMethod("POST");
return conn;当我用conn.getInputStream();的时候就会有java.io.FileNotFoundException: http://xxx...jpg
什么网站什么图片都这样。
我就日了。搞了一整天了。google了。有人说中文字符。中文你妹啊。
木有中文字符!
但是就是有问题。
相信我,说找不到地址的那个。我跑到其他机子去开也能开的出来,本机的浏览器也能开。我擦。。谁能告诉我怎么回事?
URL url = new URL(uriPath);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(5 * 1000);
//conn.setRequestProperty("Accept", "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
conn.setRequestProperty("Accept-Language", "zh-CN");
conn.setRequestProperty("Charset", "UTF-8");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
//要是不设置为post的话。就会在手机上面(不是模拟器)出现connection reset 之类的错误!
conn.setRequestMethod("POST");
return conn;当我用conn.getInputStream();的时候就会有java.io.FileNotFoundException: http://xxx...jpg
什么网站什么图片都这样。
我就日了。搞了一整天了。google了。有人说中文字符。中文你妹啊。
木有中文字符!
但是就是有问题。
相信我,说找不到地址的那个。我跑到其他机子去开也能开的出来,本机的浏览器也能开。我擦。。谁能告诉我怎么回事?
解决方案 »
- 使用My97DatePicker浏览器出现不了日期框
- 求一个下拉框联动实例(非AJAX)
- ^-^让新闻每访问一次,阅读次数就加一,不知道错在那里,大家帮忙^-^
- jbuilder2007怎么开发struts?
- 刷新相当于添加一条记录
- 如何取得当前执行javaBean的物理路径?
- Servlet使用tomcat执行时显示unknown database 'bookstore'
- 请到http://220.114.108.6:8080/jxc添加条记录
- 求助!jsp页面代码执行次序问题!!急!!
- 微信高级群发接口问题 根据OpenID列表群发 错误码40032
- struts2 s:autocompleter不起作用
- jsp中显示查询结果的问题
没有文件啊!
浏览器打开这个看看这个有没有http://xxx...jpg
否则的话网线没有插好!可能连不上网
上面也说了。这个可以能够打开图片。图片路径没有错。
我甚至自己在本机试了一下tomcat自己弄了张图片。路径:127.0.0.1,localhost。192.168.1.X都试过了。结果也是这个异常。我就擦了。
到底怎么回事呢
你确定是这行?
<html>
<head>
<script type="text/javascript">
function check()
{var x=document.getElementById("password");
var y=document.getElementById("pasword1");
if(x!=y){alert{"两次密码输入不相同!";return false }
}
</script> <title>newOperator</title>
</head>
<body>
<form name="myname" action="" method="post" onsubmit="check();" >
密码:<input type="password" id="password" value=""/></br>
密码确认:<input type="password" id="password1" value=""/></br>
<input type="submit" name="sbt" value="提交"/><br>
</form>
</body>
这个脚本程序为什么就不执行
LZ我很同情你 我出现过跟你一样的情况~~!~!
跪求高手解决问题!!!
路径是全英文的。不是中文。所以也不说字符问题了
URL url = new URL("http://rewalls.com/pic/201112/1680x1050/reWalls.com-55897.jpg");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("GET");
try (InputStream in = connection.getInputStream()){
Files.copy(in, Paths.get("/tmp","image.jpg"), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
如果是POST
java.io.IOException: Server returned HTTP response code: 411 for URL: http://rewalls.com/pic/201112/1680x1050/reWalls.com-55897.jpg
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1612)
at Example.main(Example.java:19)
URLConnection conn = url.openConnection(); // 建立连接
InputStream in = conn.getInputStream(); // 获得输入流
// 设置输入流的字符集
InputStreamReader reader = new InputStreamReader(in,"gbk");
BufferedReader br = new BufferedReader(reader);
String data = br.readLine(); // 开始读取数据
while(data != null){
if(data == "<head>"){
}
System.out.println(data);
data = br.readLine();
}
br.close();
in.close();
试试这个
throws IOException Returns an input stream that reads from this open connection. Returns:
an input stream that reads from this open connection.
Throws:
IOException - if an I/O error occurs while creating the input stream.
UnknownServiceException - if the protocol does not support input.这个真的会抛出FileNotFoundException吗?
是否用了File f = new File(...); 或者FileInputStream/FileOutputStream?
有些服务器post的时候就会出错。所以只能用get。下次我就把图片给上了。