如何成为Android开发高手
2010-08-31 00:43:00 来源:WEB开发网134
135 byte[] buffer = new byte[1024];
136
137 int len = 0;
138
139 while((len = file.getInStream().read(buffer))!=-1){
140
141 outStream.write(buffer, 0, len);
142
143 }
144
145 file.getInStream().close();
146
147 }else{
148
149 outStream.write(file.getData(), 0, file.getData().length);
150
151 }
152
153 outStream.write(" ".getBytes());
154
155 }
156
157 byte[] end_data = ("--" + BOUNDARY + "-- ").getBytes();//数据结束标志
158
159 outStream.write(end_data);
160
161 outStream.flush();
162
163 int cah = conn.getResponseCode();
164
165 if (cah != 200) throw new RuntimeException("请求url失败");
166
167 InputStream is = conn.getInputStream();
168
169 int ch;
170
171 StringBuilder b = new StringBuilder();
172
173 while( (ch = is.read()) != -1 ){
174
175 b.append((char)ch);
176
177 }
178
179 outStream.close();
180
181 conn.disconnect();
182
183 return b.toString();
184
185 } catch (Exception e) {
186
187 throw new RuntimeException(e);
188
189 }
190
191}
192
193
194
195/**
196
197 * 提交数据到服务器
198
199 * @param actionUrl 上传路径(注:避免使用localhost或127.0.0.1这样的路径测试,因为它会指向手机模拟器,你可以使用http://www.itcast.cn或http://192.168.1.10:8080这样的路径测试)
200
更多精彩
赞助商链接