【问题标题】:Multipart Request多部分请求
【发布时间】:2015-02-13 08:45:52
【问题描述】:

使用 Retrofitspring-data-rest 实例发出请求,发送多部分请求时遇到问题。

改造

@Multipart
@POST(URI)
void save(@Part("request[data][param][event]") Event event,
          Callback<Resource<Event>> callback);

春天

@RequestMapping(value=URI, method=RequestMethod.POST)
public @ResponseBody HttpEntity<Event> addEvent(@RequestPart Event event) {
    ...
}

这样,我收到 400 错误请求“所需的请求部分‘事件’不存在。”

假设 Event 对象有一个字符串名称和位图图像,那么正确的处理方法是什么?

【问题讨论】:

    标签: retrofit spring-data-rest


    【解决方案1】:

    差不多了,保存方法签名应该是:

    @Multipart
    @POST(URI)
    void save(@Part("event") Event event,
              Callback<Resource<Event>> callback);
    

    【讨论】:

    • 这种方法没有t work at me. server says:"Required MultipartFile parameter 'file' is not present","path":"/backend/newimage". Put I have a @Part("file") param, so I dont userstand
    • @Karoly 你可以为你的服务器端和客户端代码做一个 Gist(gist.github.com) 吗?我愿意看一下。
    • 请在这里找到我的问题:stackoverflow.com/questions/31121212/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-26
    • 2015-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多