【问题标题】:"missing boundary headers" with ws.url in scala playscala play中带有ws.url的“缺少边界标题”
【发布时间】:2017-03-20 01:46:13
【问题描述】:

我正在使用以下代码针对虚拟端点测试服务:

ws.url(dummyService).withHeaders(HeaderNames.CONTENT_TYPE -> "multipart/form-data; boundary=-----{}}AAA{{}-----").post(myData)

这会生成请求,标头设置正确。

在我的模拟服务中,我像这样处理响应:

def checkData = Action(parse.multipartFormData) { request =>
    request.body.files.find(_.filename.endsWith("testfail.pdf")) match {
      case Some(invalidFile) => BadRequest("Parse Fail")
      case None => Ok("Parse Success")
    }
  }

当我运行测试时,我收到错误 400 和以下消息:

For request 'POST /TEST/process' [Missing boundary header]

我做错了什么?

【问题讨论】:

    标签: scala playframework-2.5


    【解决方案1】:

    为了使用Action(parse.multipartFormData),您必须确保相应的 POST 请求使用multipart/form-data (more on when to use it) 的表单编码。

    换句话说,您可能希望像这样在模板中定义表单:

    @helper.form(action = routes.MyApp.upload, 'enctype -> "multipart/form-data") {
      // ...
    }
    

    发送具有不同编码的 POST 会导致 [Missing boundary header] 错误。

    【讨论】:

      猜你喜欢
      • 2020-03-31
      • 1970-01-01
      • 2019-03-07
      • 1970-01-01
      • 2014-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-28
      相关资源
      最近更新 更多