标签: multipartentity

Apache HttpClient Android(Gradle)

我已将此行添加到build.gradle中

compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
Run Code Online (Sandbox Code Playgroud)

我想在我的代码中使用MultipartEntityBuilder.但Android Studio不会将库添加到我的代码中.谁能帮我这个?

android gradle apache-httpcomponents multipartentity android-studio

52
推荐指数
4
解决办法
13万
查看次数

设置Multipart Entity的编码

我想将UTF-8编码设置为MultipartEntity对象或StringBody对象.有什么办法吗?我知道如何设置Charset而不是编码.

谢谢.

java android multipartentity

17
推荐指数
1
解决办法
1万
查看次数

是否可以在多部分POST中使用嵌套的MultipartEntities或FormBodyPart?

我正在尝试使用MultipartEntity创建以下服务器POST请求:

parameters: {"parameter1"=>"parameter1", "parameter2"=>{"sub_parameter1"=>"sub_parameter1", "sub_parameter2"=>"sub_parameter2"}}
Run Code Online (Sandbox Code Playgroud)

我目前正在使用类似的东西:

multipartEntity.addPart("parameter1", new StringBody("parameter1"));

FormBodyPart parameter2 = new FormBodyPart("parameter2", new StringBody("")); // It wouldn't allow a null ContentBody

parameter2.addField("sub_parameter1", "sub_parameter1");
parameter2.addField("sub_parameter2", "sub_parameter2");
Run Code Online (Sandbox Code Playgroud)

但是,子字段不会携带.我得到:

parameters: {"parameter1"=>"parameter1", "parameter2"=>""}
Run Code Online (Sandbox Code Playgroud)

如何在MultipartEntity或它包含的FormBodyPart元素中创建嵌套结构?

apache android http multipartentity

13
推荐指数
1
解决办法
962
查看次数

Android错误:MultipartEntity,客户端发送的请求在语法上不正确

我想通过安全的restful web服务发送歌曲(mp3/wav)文件和一些数据.我正在使用MultipartEntity来发出HttpPost请求.但是当我通过HttpClient执行它时,服务器会回复此错误

HTTP状态400 - 错误请求类型:状态报告消息:错误请求客户端发送的请求在语法上不正确(错误请求).

但是,如果我们从Web界面调用它,那么该服务的效果非常好.请帮忙

它的代码

HttpClient httpclient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost();
        try {
            MultipartEntity reqEntity = new MultipartEntity();

            reqEntity.addPart("email", new StringBody("test@testmail.com"));
            reqEntity.addPart("password", new StringBody("123"));
            reqEntity.addPart("title", new StringBody("My new song"));
            reqEntity.addPart("musicData", new FileBody(new File(FilePath))); 

            // FIlePath is path to file and contains correct file location

            postRequest.setEntity(reqEntity);

            postRequest.setURI(new URI(ServiceURL));
            HttpResponse response = httpclient.execute(postRequest);

        } catch (URISyntaxException e) {
            Log.e("URISyntaxException", e.toString());
        } 
Run Code Online (Sandbox Code Playgroud)

我还为MultipartEntity提供了apache-mime4j,httpclient,httpcore和httpmime jar.

这是服务的HTML页面捕捉. 在此输入图像描述

java android httpclient http-post multipartentity

12
推荐指数
1
解决办法
2939
查看次数

如何打印/记录HTTPRequest正在使用的MultiPartEntity的整个正文内容?

我想验证HTTP请求中究竟是什么,即参数和标题.我正在调试的代码在执行HTTP请求之前使用MultiPartEntity来设置setEntity.

response = executePost(multipartEntity);
statusCode = response.statusCode;
Run Code Online (Sandbox Code Playgroud)

我没有从服务器获得预期的响应,因此想要验证发送到服务器的确切事物(url +参数).

谢谢.

java android http httprequest multipartentity

12
推荐指数
1
解决办法
6847
查看次数

Android:使用MultiPartEntityBuilder上传Image和JSON

我尝试将数据上传到服务器,我的数据包含多个图像和大JSON,在它之前,我尝试使用转换图像发送到字符串使用base64并发送我之前转换的另一个数据和图像JSON,但我OutOfMemory在这里遇到问题,所以我读了一个说我必须尝试使用​​的解决方案MultipartEntityBuilder.我仍然感到困惑,不明白该怎么做MultiPartEntityBuilder,有没有人可以帮助我这样做MultiPartEntityBuilder?这是我的代码:

    try{
    //membuat HttpClient
    //membuat HttpPost
    HttpPost httpPost= new HttpPost(url);
    SONObject jsonObjectDP= new JSONObject();
    System.out.println("file audio "+me.getModelDokumenPendukung().getAudio());
    jsonObjectDP.put("audio_dp",MethodEncode.EncodeAudio(me.getModelDokumenPendukung().getAudio()));
    jsonObjectDP.put("judul_audio",me.getModelDokumenPendukung().getJudul_audio());
    jsonObjectDP.put("ket_audio",me.getModelDokumenPendukung().getKet_audio());
    JSONArray ArrayFoto= new JSONArray();

    //This loop For my multiple File  Images
    List<ModelFoto>ListFoto=me.getModelDokumenPendukung().getListFoto();
    for (int i=0; i<ListFoto.size();i++) {
        JSONObject jsonObject= new JSONObject();
        jsonObject.put("foto", ListFoto.get(i).getFile_foto());
        jsonObject.put("judul_foto", ListFoto.get(i).getJudul_foto());
        jsonObject.put("ket_foto", ListFoto.get(i).getKet_foto());
        ArrayFoto.put(jsonObject);

    }

    JSONObject JSONESPAJ=null;
     JSONESPAJ = new JSONObject();
     JSONObject JSONFINAL = new JSONObject();
            JSONESPAJ.put("NO_PROPOSAL",me.getModelID().getProposal());
            JSONESPAJ.put("GADGET_SPAJ_KEY",me.getModelID().getIDSPAJ());
            JSONESPAJ.put("NO_VA",me.getModelID().getVa_number());
            JSONESPAJ.put("Dokumen_Pendukung",jsonObjectDP);

            JSONFINAL.put("ESPAJ", JSONESPAJ); …
Run Code Online (Sandbox Code Playgroud)

android json http-post multipartentity

12
推荐指数
1
解决办法
3万
查看次数

更改android中多部分文件上传中每个突发的长度

有没有办法限制从org.apache.http.entity.mime.MultipartEntity在MultipartEntity上发送的零件尺寸.我正在使用凌空的网络请求.我试过扩展Volley请求类并重写getbody()方法.

android multipartentity apache-httpclient-4.x

10
推荐指数
0
解决办法
108
查看次数

@Part参数只能与多部分编码一起使用.(参数#8)

在我在这里发布这个问题之前,我已经尝试添加@Multipart上面的接口方法并且在stackoverflow中搜索仍然找不到类似我的问题.

在这种情况下,我尝试使用TypedFile服务器发送图像.我的界面方法如下所示:

 @Headers({"Content-type: application/json"})
    @POST("/user/change")
    void postChange(@Query("name") String name, @Query("email") String  email, @Query("password") String password, @Query("phone") String phone, @Query("user_id") String userId, @Query("address[]") String[] listAddress, @Query("head[]") String[] head, @Part("photo_profile") TypedFile photoProfile, @Body TypedInput jsonObject, Callback<ReceiveDTO> callback);
Run Code Online (Sandbox Code Playgroud)

编辑

在那种方法中,我们可以看到@Part@Body.如果我添加@Multipart上面的方法,我们将抛出一个错误@Body parameters cannot be used with form or multi-part encoding. (parameter #9)

我正在使用Retrofit 1.9

android multipartentity retrofit

10
推荐指数
2
解决办法
1万
查看次数

HTTP multipart和chunking可以共存吗?

我使用Apache HttpClient发布多个文件服务器.这是代码:

    public static HttpResponse stringResponsePost(String urlString, String content, byte[] image,
        HttpContext localContext, HttpClient httpclient) throws Exception {

    URL url = new URL(URLDecoder.decode(urlString, "utf-8"));
    URI u = url.toURI();

    HttpPost post = new HttpPost();
    post.setURI(u);

    MultipartEntity reqEntity = new MultipartEntity();
    StringBody sb = new StringBody(content, HTTP_CONTENT_TYPE_JSON, Charset.forName("UTF-8"));
    ByteArrayBody ib = new ByteArrayBody(image, HTTP_CONTENT_TYPE_JPEG, "image");

    reqEntity.addPart("interview_data", sb);
    reqEntity.addPart("interview_image", ib);
    post.setEntity(reqEntity);

    HttpResponse response = null;
    response = httpclient.execute(post, localContext);

    return response;
}
Run Code Online (Sandbox Code Playgroud)

问题是,MultipartEntityclass只有isChunked()方法(总是返回false),如果我希望为我的multipart实体启用chucked编码,则没有"setChunked(boolean)"选项.

我的问题是:

  1. HTTP multipart和chunking可以根据协议规范共存吗?如果不是,为什么像其他实体 …

java http chunked-encoding http-chunked multipartentity

7
推荐指数
1
解决办法
3934
查看次数

库和从输入流解析multipart/form-data的示例

我发送的一种HTTP请求的响应是multipart/form-data看起来像:

--------boundary123
Content-Disposition: form-data; name="json"
Content-Type: application/json

{"some":"json"}
--------boundary123
Content-Disposition: form-data; name="bin"
Content-Type: application/octet-stream

<file data>

--------boundary123
Run Code Online (Sandbox Code Playgroud)

我一直在使用apache发送和接收HTTP请求,但我似乎无法找到一种简单的方法来使用它来解析上面的内容以便于访问表单字段.

我宁愿不重新发明轮子,所以我正在寻找一个允许我做类似的工作的库:

MultipartEntity multipart = new MultipartEntity(inputStream);
InputStream bin = multipart.get("bin");
Run Code Online (Sandbox Code Playgroud)

有什么建议?

java parsing http multipartform-data multipartentity

7
推荐指数
2
解决办法
2万
查看次数