如何成为Android开发高手
2010-08-31 00:43:00 来源:WEB开发网080
081 conn.setDoOutput(true);//允许输出
082
083 conn.setUseCaches(false);//不使用Cache
084
085 conn.setRequestMethod("POST");
086
087 conn.setRequestProperty("Connection", "Keep-Alive");
088
089 conn.setRequestProperty("Charset", "UTF-8");
090
091 conn.setRequestProperty("Content-Type", MULTIPART_FORM_DATA + "; boundary=" + BOUNDARY);
092
093
094
095 StringBuilder sb = new StringBuilder();
096
097 for (Map.Entry
098
099 sb.append("--");
100
101 sb.append(BOUNDARY);
102
103 sb.append(" ");
104
105 sb.append("Content-Disposition: form-data; name=\""+ entry.getKey() + "\" ");
106
107 sb.append(entry.getValue());
108
109 sb.append(" ");
110
111 }
112
113 DataOutputStream outStream = new DataOutputStream(conn.getOutputStream());
114
115 outStream.write(sb.toString().getBytes());//发送表单字段数据
116
117 for(FormFile file : files){//发送文件数据
118
119 StringBuilder split = new StringBuilder();
120
121 split.append("--");
122
123 split.append(BOUNDARY);
124
125 split.append(" ");
126
127 split.append("Content-Disposition: form-data;name=\""+ file.getFormname()+"\";filename=\""+ file.getFilname() + "\" ");
128
129 split.append("Content-Type: "+ file.getContentType()+" ");
130
131 outStream.write(split.toString().getBytes());
132
133 if(file.getInStream()!=null){
更多精彩
赞助商链接