【问题标题】:Different content type for different elements of form data表单数据的不同元素的不同内容类型
【发布时间】:2018-02-26 16:02:11
【问题描述】:

我无法使用表单数据的第一个元素发送content-type application/json

我的代码:

var fd = new FormData();
fd.append('addBank', JSON.stringify(reqData.addBank[0]));
fd.append('bankProof', reqData.bankProof);
var promise  = $http.post(url, fd, { transformRequest: angular.identity, headers: {'Content-Type': undefined}});

当我尝试为第一个键值对设置 content-type 时,它会使请求中的数据变为空白。

【问题讨论】:

  • 预期结果是什么?
  • Content-Type: application/json 为 addBank 设置

标签: javascript jquery angularjs json multipartform-data


【解决方案1】:

您可以将附加到FormData 对象的值设置为Blob,并将数据设置为JSONtype 设置为"application/json"

fd.append("addBank"
, new Blob([JSON.stringify(reqData.addBank[0])], {type:"application/json"}));

【讨论】:

  • 没有获取 addBank 的数据------ WebKitFormBoundaryaRSVPSAq0VUhqJ8l Content-Disposition: form-data;名称="添加银行"; filename="blob" Content-Type: application/json ------WebKitFormBoundaryaRSVPSAq0VUhqJ8l Content-Disposition: form-data;名称="银行证明"; filename="kyc.jpg" Content-Type: image/jpeg ------WebKitFormBoundaryaRSVPSAq0VUhqJ8l--
  • “未获取数据”是什么意思?
  • 它没有发送 json。该密钥的请求为空
  • @PurvaArora “它没有发送 json。该密钥的请求是空白的” 你如何确定 FormData 在请求时反对 POSTed “那个键的空白”?
  • -----WebKitFormBoundarylFvcylcNTGG07ARG 内容处置:表单数据;名称="添加银行"; filename="blob" Content-Type: application/json ------WebKitFormBoundarylFvcylcNTGG07ARG Content-Disposition: form-data;名称="银行证明"; filename="kyc.jpg" Content-Type: image/jpeg ------WebKitFormBoundarylFvcylcNTGG07ARG--
猜你喜欢
  • 1970-01-01
  • 2010-11-21
  • 2020-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-16
  • 2013-06-02
  • 1970-01-01
相关资源
最近更新 更多