new Thread(new Runnable() {
@Override
public void run() {
FileOutputStream outputStream = null;
try {
URL url = new URL("http://www.9610.com/song/baiyuchan/baiyuchan.jpg");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.connect();
byte[] buffer = new byte[1024];
File file = new File(Environment.getExternalStorageDirectory() + "/" + "downloaddd", "baiyuchan.jpg");
outputStream = new FileOutputStream(file);
int length = 0;
int finalFileSize = connection.getContentLength();
int downloadSize = 0;
InputStream input = connection.getInputStream();
while ((len = input.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
downloadSize = downloadSize + len;
float progress = downloadSize / (float) finalFileSize;
/* Log.i("tag", "data:"
+ new String(buffer, 0, len));*/
System.out.println(progress);
}
outputStream.flush();
outputStream.close();
// input.close();
// connection.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
if (outputStream!=null){
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
报错System.err: java.io.FileNotFoundException: http://www.9610.com/song/baiyuchan/baiyuchan.jpg
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:207)
求指点哪里写错了?返回的connection.getResponseCode()是405 该称“GET”方法就可以了,但是想用“POST”来做要怎么修改呢?
http://www.9610.com/song/baiyuchan/baiyuchan.jpg
这个图片只提供了GET请求,不支持POST去修改