【问题标题】:Getting 415 - Unsupported Media Type in Postman post method获取 415 - Postman post 方法中不支持的媒体类型
【发布时间】:2017-08-17 04:12:31
【问题描述】:

我使用邮递员 (https://www.getpostman.com/) 来测试我的 API API 在 AWS ApiGateway 和 Lambda 函数 (NodeJS) 中

(1) 当我第一次向服务器发送 post 方法请求时,它会给出正确的响应,我现在没有发送任何 post 参数。

这是请求标头-

Connection →keep-alive
Content-Length →61
Content-Type →application/json
Date →Fri, 24 Mar 2017 09:09:13 GMT
Via →1.1 440f7503597ca64245c4258c03b08e0c.cloudfront.net (CloudFront)
X-Amz-Cf-Id →t50_SeWgC3Qb2ZFtf4fksUTdi5viINCaAEj8MPTvhRbtMHu-LK1mwA==
X-Amzn-Trace-Id →Root=1-58d4e239-76404c1ab9912d010fac33a2
X-Cache →Miss from cloudfront
x-amzn-RequestId →8c8f9bd2-1071-11e7-9490-79b68cde95e0

这是回复

{
  "response": "false",
  "message": "Please enter a valid email !"
}

当没有 post 参数发送到请求时,它工作正常。

(2) 现在,当我向 request 发送一些参数时, 请求标头更改并删除了一个标头 prama X-Amzn-Trace-Id

这是请求标头-

Connection →keep-alive
Content-Length →37
Content-Type →application/json
Date →Fri, 24 Mar 2017 09:02:52 GMT
Via →1.1 d6cd0a105a9b074288944d270dfa7321.cloudfront.net (CloudFront)
X-Amz-Cf-Id →UZLUL1lYwAIrnwaa7kPVrPBx462sa7sV0x0WFQFGJ2OXVbrp9gaNYg==
X-Cache →Error from cloudfront
x-amzn-RequestId →a9c4116a-1070-11e7-b08c-c3cf73411cde

这是请求正文

{
"userEmail":"rahul@gmail.com",
"userPasswod":"123456",
"userName":"rahul"
}

这是回复

{
  "message": "Unsupported Media Type"
}

经过大量研发后,我还在标题中添加了content/Type- application/json,但仍然得到相同的响应。

请有人帮我弄清楚邮递员的这个问题。

【问题讨论】:

  • 服务器端的 API 是否支持 application/json 内容类型?您可以在服务器端发布处理此请求的代码吗?
  • 是的,它支持 application/json 内容类型。我正在研究 AWS lambda 函数和 api 网关

标签: rest api amazon-web-services postman


【解决方案1】:

我在使用 postman 和 aws 时也有类似的经历。我可以在 AWS 中进行适当的响应测试,但是当我在邮递员中进行测试时,我会得到“不支持的媒体类型”,我在邮递员中通过选择“正文”选项卡,然后选择原始单选按钮,然后选择 JSON(application/json) 来解决它在下拉列表中。最后,我填写了类似于我在 AWS 中的测试数据的原始数据。它看起来像这样:

postman image

希望对你有帮助,祝你好运!

【讨论】:

  • 是的,我知道,它使用原始数据,但我需要知道为什么它不能使用表单数据。
猜你喜欢
  • 2021-05-20
  • 2022-01-15
  • 2019-03-23
  • 1970-01-01
  • 1970-01-01
  • 2020-09-03
  • 2017-03-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多