【问题标题】:Ajax request does not work outside of Postman environment - 400 (Bad Request)Ajax 请求在 Postman 环境之外不起作用 - 400(错误请求)
【发布时间】:2018-11-04 01:52:40
【问题描述】:

使用以下代码:

var form = new FormData(); form.append("active_registration_id", "123"); form.append("language_id", "79"); form.append("归档", "{{归档}}"); form.append("启用", "{{启用}}"); form.append("密码", "SamplePassword"); form.append("password_confirmation", "SamplePassword"); form.append("registration_attributes[first_name]", "Justin"); form.append("registration_attributes[last_name]", "Trudeau"); form.append("registration_attributes[email]", "email@sample.com"); form.append("registration_attributes[telephone_1]", "555-555-5555"); form.append("registration_attributes[date_of_birth]", "1943-10-10"); form.append("registration_attributes[gender]", "Male"); form.append("registration_attributes[referral_code]", "Ample Clinic 123"); form.append("registration_attributes[status]", "Registration Pending"); 变量设置 = { “异步”:是的, “跨域”:是的, "url": "https://www.sample.com/v2/clients?token=DMfJjzWLngIn0JBHA0gWcg", “方法”:“发布”, “标题”:{ “内容类型”:“应用程序/x-www-form-urlencoded” }, “过程数据”:假, “内容类型”:假, "mimeType": "multipart/form-data", “数据”:表格 } $.ajax(settings).done(function (response) { 控制台日志(响应); });

我们总是得到 400 (Bad Request) 和进一步的错误:{"registration_attributes":["Missing"]} 此代码将在 Postman 中工作,但不能在生产服务器上工作。我创建registration_attributes数组的方式有什么问题吗?

【问题讨论】:

    标签: ajax postman


    【解决方案1】:

    FormData设置ajax请求的内容类型,去掉你设置的内容类型头。

    附: mimeType 不是 jQuery ajax 中的字段,只需将其删除即可。

    【讨论】:

      猜你喜欢
      • 2016-04-13
      • 2018-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-21
      • 2022-11-10
      • 2021-11-29
      • 2020-09-21
      相关资源
      最近更新 更多