Android 如何使用多部分截击请求。?
我想上传多部分截击请求中的视频。只是想知道,如何使用以及如何在其中添加多部分参数。?您可以试试这是一个完整的工作代码,可以通过multapart将视频或大文件发送到服务器Android 如何使用多部分截击请求。?,android,android-volley,Android,Android Volley,我想上传多部分截击请求中的视频。只是想知道,如何使用以及如何在其中添加多部分参数。?您可以试试这是一个完整的工作代码,可以通过multapart将视频或大文件发送到服务器 public static Boolean SendPostToServer(FBPost postData, Context context, String videoPath) { try { HttpClient httpClient = new DefaultHttpClient();
public static Boolean SendPostToServer(FBPost postData, Context context, String videoPath) {
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(context.getString(R.string.url_service_post));
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
if(!videoPath.isEmpty()){
FileBody filebodyVideo = new FileBody(new File(videoPath));
reqEntity.addPart("uploaded", filebodyVideo);
}
reqEntity.addPart("userId", new StringBody(postData.userId));
reqEntity.addPart("postText", new StringBody(postData.postText));
if(postData.postId != null && postData.postId.length() > 0) {
reqEntity.addPart("postId", new StringBody(postData.postId));
}
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
Log.e("Response: ", s.toString());
return true;
} catch (Exception e) {
Log.e(e.getClass().getName(), e.getMessage());
return false;
}
}
我试试这个。但是,您确定它不会对大文件发出内存不足错误(例如:20Mb到50Mb)吗?不会,它将以块的形式发送您的数据,并且不会发出内存不足错误您是否在项目中包含了httpmime.jar文件?这不是使用截取API。此答案与截取无关!