Is it possible to have a nested MultipartEntities or FormBodyPart in a multipart POST?

前端 未结 4 1934
孤街浪徒
孤街浪徒 2021-02-13 16:44

I\'m trying to make something the following server POST request using MultipartEntity:

parameters: {\"parameter1\"=>\"parameter1\", \"parameter2\"=>{\"sub_         


        
相关标签:
4条回答
  • 2021-02-13 16:47

    Something like this:

    MultipartEntity reqEntity = new MultipartEntity();
    reqEntity.addPart("selectedGroup", new StringBody(group));
    reqEntity.addPart("selectedService", new StringBody(service.toString()));
    reqEntity.addPart("selectedTransformation", new StringBody(transformation.toString()));
    reqEntity.addPart("projectId", new StringBody(projectId.toString()));
    

    Check exapmle 8 of this link. Also exapmple 23 Example Site

    Hope this helps you with your problem.

    0 讨论(0)
  • 2021-02-13 16:50

    once you've seen how the form entries are transferred over HTTP connection, you'll understand it's impossible to have anything nested with the multiform request as well as with the url-encoded request.

    things are very simple. multipart form request has the format of:

    --- content-boundary ---
    Content-Disposition: form-data; name="form_data_name"
    
    [content (skipped)]
    --- content-boundary ---
    

    that's it. there's stream of single data form entries in the format: [form entry name] -> [form entry content] that repeats for every entry in the form. it's not recursive, therefore there may not be any nested structures.

    Sources:

    1. 17.13.4 Form content types
    2. RFC 2045 Internet Message Bodies
    0 讨论(0)
  • 2021-02-13 16:56

    Consider sending a json in the body of the request. That way you can send whatever you want.

    0 讨论(0)
  • 2021-02-13 17:08

    why dont you post whole Json object instead of post each string value of Json object.

    Go through this link http://hmkcode.com/android-send-json-data-to-server/

    0 讨论(0)
提交回复
热议问题