Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用多部分截击请求。?_Android_Android Volley - Fatal编程技术网

Android 如何使用多部分截击请求。?

Android 如何使用多部分截击请求。?,android,android-volley,Android,Android Volley,我想上传多部分截击请求中的视频。只是想知道,如何使用以及如何在其中添加多部分参数。?您可以试试这是一个完整的工作代码,可以通过multapart将视频或大文件发送到服务器 public static Boolean SendPostToServer(FBPost postData, Context context, String videoPath) { try { HttpClient httpClient = new DefaultHttpClient();

我想上传多部分截击请求中的视频。只是想知道,如何使用以及如何在其中添加多部分参数。?

您可以试试这是一个完整的工作代码,可以通过multapart将视频或大文件发送到服务器

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。此答案与截取无关!