Android网络操作(上传下载等)(3)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-15 19:49 点击:次
private static String retrieveHttpEntity(HttpEntity httpEntity) throws UnsupportedEncodingException, IllegalStateException,
IOException {
StringBuffer stringBuffer = new StringBuffer();
InputStreamReader is = new InputStreamReader(httpEntity.getContent(), HTTP.UTF_8);
BufferedReader bufferedReader = new BufferedReader(is);
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line);
}
return stringBuffer.toString();
}
public static String uploadFile(String actionUrl, String newName, InputStream fStream) {
String end = "\r\n";
String twoHyphens = "--";
String boundary = java.util.UUID.randomUUID().toString();
DataOutputStream ds = null;
try {
URL url = new URL(actionUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
/* 允许Input、Output,不使用Cache */
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
/* 设定传送的method=POST */
con.setRequestMethod("POST");
/* setRequestProperty */
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Charset", "UTF-8");
con.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>