UI5应用调用DocuSign创建信封遇400错误:无法解析multipart body
解决UI5应用调用DocuSign接口报"Unable to parse multipart body"的400错误
我来帮你排查这个问题——核心矛盾是UI5里的jQuery AJAX请求和Postman请求表现不一致,这个400错误明确指向请求体解析失败,大概率是jQuery的默认配置在悄悄修改你的请求格式,咱们一步步解决:
关键问题:jQuery的默认数据处理行为
你已经手动把请求体用JSON.stringify()转成了字符串,但jQuery的AJAX默认会对data参数做编码处理(即使你设置了Content-Type: application/json)。它会把字符串当成表单数据来处理,自动添加额外的编码,导致DocuSign收到的请求体格式混乱,无法解析。而Postman是直接发送纯JSON字符串,所以能成功。
解决方案:添加processData: false配置
在你的AJAX设置里加上processData: false,告诉jQuery不要处理已经序列化好的JSON字符串,直接原样发送。同时建议把Content-Type通过contentType属性设置(比在headers里设置更可靠,避免jQuery覆盖):
修改后的代码示例:
var settings = { "async": true, "crossDomain": true, "url": "/docusign/envelopes", "method": "POST", "timeout": 0, "headers": { "Authorization": "User DnVj27euWrCi4ANoMV5puvxVxYAcUCG3PlkUSpWpC08=, Organization 6ba64ce816dec995b17d04605e329a30, Element X4XuUq/T5UUh2o9xwaamZCCRwOKUCPr1Kv1Nj+qHPj0=" }, "contentType": "application/json", // 明确设置JSON内容类型 "processData": false, // 禁止jQuery自动处理请求数据 "data": JSON.stringify({ "status": "sent", "compositeTemplates": [{ "compositeTemplateId": "1", "inlineTemplates": [{ "recipients": { "signers": [{ "email": "johndoe@testmail.com", "name": "John Doe", "recipientId": "1", "roleName": "Signer", "clientUserId": "12345", "tabs": { "textTabs": [{ "tabLabel": "firstName", "value": "John" }, { "tabLabel": "lastName", "value": "Doe" }, { "tabLabel": "phoneNo", "value": "022-635363" }, { "tabLabel": "email", "value": "test@gmail.com" }] } }] }, "sequence": "1" }], "serverTemplates": [{ "sequence": "1", "templateId": "0bf97611-a457-4e8e-ac7e-1593c17ba3f6" }] }] }) }; var deferred = $.Deferred(); $.ajax(settings) .done(function (response) { deferred.resolve(response); }.bind(this)) .fail(function (error) { deferred.reject(error); }.bind(this));
额外排查步骤
如果修改后还是报错,建议通过浏览器开发者工具确认实际发送的请求是否和Postman一致:
- 打开Chrome开发者工具(按F12),切换到Network标签
- 触发请求,找到对应的POST请求(
/docusign/envelopes) - 查看Request Headers,确认
Content-Type是否为application/json - 查看Payload,确认请求体是纯JSON字符串,没有被额外编码成表单格式
另外,如果你是通过UI5代理访问DocuSign接口,要确保代理没有修改请求体或请求头,比如是否正确传递了Content-Type和JSON内容。
内容的提问来源于stack exchange,提问作者Kaz2310
相关产品推荐
相关产品推荐

