【问题标题】:the request was rejected because no multipart boundary was found in Grails请求被拒绝,因为在 Grails 中没有找到多部分边界
【发布时间】:2013-05-10 18:03:15
【问题描述】:

我正在尝试发送内容类型为 multipart/mixed 的请求

只需在我的控制器中使用println params这一行打印请求

但是,我不断收到错误消息:the request was rejected because no multipart boundary was found

我不确定这是 grails 中的问题还是我的请求搞砸了。我正在使用 RESTConsole 并将内容类型设置为 multipart/mixed 并将以下内容作为 RAW Body 发送:

--boundary42 
Content-Type: text/plain; charset=us-ascii 

...plain text version of message goes here.... 

--boundary42 
Content-Type: text/richtext 

.... richtext version of same message goes here ... 
--boundary42 

【问题讨论】:

    标签: http grails mime multipart


    【解决方案1】:

    multipart/mixed content-type 用于带有attachmenttext/plain 请求。请求中有附件吗?如果您不向请求发送附件,那么它将抱怨多部分边界。

    尝试添加一个附件(比如在 REST 控制台中的请求中添加一个虚拟文件),您应该会看到它工作正常。

    此内容类型主要用于电子邮件内容 [SMTP]。遵守边界,text/plain 内容将转换为消息体。您可以获取邮件正文为HttpServletRequest.getInputStream

    【讨论】:

    • 如果我发送附件,错误就会消失,但现在 println params 不会打印随附件一起发送的 text/plain
    • 如果我在原始请求正文中设置了firstName=John&lastName=Doe(查询参数字符串),它对我有用。以this answer为例。
    • 不幸的是,如果我这样做,我看不到打印的参数。请看一下这个截图:postimg.org/image/ln8exg0d3(请注意,我有查询字符串和附件)我在控制台中看到的屏幕截图是:params: [FIPS.png:org.springframework.web.multipart.commons.CommonsMultipartFile@6381db12, FIPS:[png:org.springframework.web.multipart.commons.CommonsMultipartFile@6381db12], action:[POST:save, GET:show, DELETE:delete, PUT:update], controller:mycontroller]
    • 哎呀小混混,当content-type为multipart/mixed时,请求体中不需要参数,可以在POST时使用查询字符串。在 REST 控制台中使用 Request Parameters 部分。
    • 谢谢。那可行。控制器正在查看请求参数。那么这样(上传文件并发送查询字符串)文件上传会进入请求正文吗?我试图以某种方式模仿 dropbox api 的工作方式,我还问了一个单独的问题stackoverflow.com/questions/16578475/…感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 2020-08-27
    • 2020-11-21
    • 1970-01-01
    • 2013-07-02
    • 2019-03-18
    • 1970-01-01
    • 2015-09-14
    • 2016-06-30
    相关资源
    最近更新 更多