HarmonyOS 将参数以formData的格式传给后端,但是接口报500?

有个页面需要将参数以formData的格式传给后端,但是接口报500,请求头也改为了multipart/form-data ,看下是什么原因导致的,怎么处理?

async RepairSubmit() {
  try {
    const token = this.token.access_token
    const formData = new FormData()
    formData.append("userNote", this.remarks)
    formData.append("repairName", this.PartUserinfo.contacts)
    formData.append("repairCall", this.PartUserinfo.mobile)
    formData.append("gasUserNumber", this.SingleUserInfo?.userCode)
    formData.append("detailedAddress", this.SingleUserInfo?.address)
    formData.append("type", 'BJG_Repair')
    formData.append("subType", this.SingleRepairTypes?.value)
    formData.append("bigType", 'Repair_Security')
    formData.append("appContactId", this.AllUserinfo.appContactId)
    formData.append("userId", this.PartUserinfo.userId)
    formData.append("file", this.PartUserinfo.contacts + "-报修-.jpg")
    const rr = formData.get("userNote") as string
    console.log(JSON.stringify(rr))
    const res = await req.request(Baseurl + '/i/api/repairs/nsaddrepairs', {
      method: http.RequestMethod.POST,
      header: {
        ContentType: 'multipart/form-data;',
        Authorization: `Bearer ${token}`
      },
      extraData: formData
    })
    const result = res.result
    AlertDialog.show({ message: JSON.stringify({ result }) })
    console.log('安全问题保修参数',
      JSON.stringify('userNote:' + this.remarks + " " + 'repairName:' + this.PartUserinfo.contacts + " " +
        "repairCall:" + this.PartUserinfo.mobile
        + " " + 'gasUserNumber:' + this.SingleUserInfo?.userCode + ' ' + 'detailedAddress:' +
        this.SingleUserInfo?.address + ' ' + 'type:BJG_Repair' + " "
        + 'subType:' + this.SingleRepairTypes?.value + ' ' + 'bigType: Repair_Security' + " " + 'appContactId:' +
      this.AllUserinfo.appContactId + " " + "userId:" + this.PartUserinfo.userId
      ))
    console.log('安全问题保修参数接口', Baseurl + '/i/api/repairs/nsaddrepairs')

  } catch (e) {
    console.log('安全问题保修', e)
  }
}
阅读 523
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进