简体   繁体   English

摆脱邮递员请求中的内容类型

[英]Get rid of Content-type in postman request

I have changed my app so that it sets Content-type to application/json in case if the header is absent and now trying to test it. 我已经更改了我的应用程序,因此如果标题不存在并且现在尝试测试它,它会将Content-typeapplication/json

For this purpose I use Postman. 为此我使用Postman。 However, when I uncheck "Content-type" header in "Headers" tab Postman still sends Content-type=text/plain;charset=UTF-8 . 但是,当我取消选中“标题”选项卡中的“内容类型”标题时,邮递员仍会发送Content-type=text/plain;charset=UTF-8

Is there a way to avoid this and just not send anything in Content-type header? 有没有办法避免这种情况,只是不在Content-type标题中发送任何Content-type

Would appreciate any help, thanks 非常感谢任何帮助,谢谢

Go to the body tab, select 'raw' from the sub menu. 转到正文选项卡,从子菜单中选择“原始”。 To the right of 'binary' in the sub menu, a picklist will be available. 在子菜单中的“二进制”右侧,将有一个选项列表。 Select 'Text' (not 'Text[text/plain]') from this list. 从此列表中选择“文本”(不是“文本[文本/普通]”)。 This will remove the Content-Type header. 这将删除Content-Type标头。 在此输入图像描述

There are two worrying things here. 这里有两个令人担忧的事情。

so that it sets Content-type to application/json 所以它将Content-type设置为application / json

Are you saying you want request bodies to be interpreted as JSON even if they do not specify it as JSON? 您是否希望将请求主体解释为JSON,即使它们未将其指定为JSON? WHY?! 为什么?! This can lead to all sorts of confusion, future frameworks could have weird defaults triggered, and failing to be specific now is going to bite in the future. 这可能会导致各种各样的混乱,未来的框架可能会触发奇怪的默认值,而现在未能具体化将在未来发生。

Are you maybe confusing Content-Type and Accept? 你可能会混淆Content-Type和Accept吗? I see that happen a lot. 我看到这种情况发生了很多。

Also another bit seemed odd: 另外一点似乎很奇怪:

and now trying to test it. 现在试图测试它。

Why are you testing "in the browser" like this? 你为什么要像这样“在浏览器中”进行测试? APIs are easily tested with integration tests, where you fire a few headers at your controller and see how it responds. API可以通过集成测试轻松测试,您可以在控制器上触发几个标题并查看它的响应方式。

it 'is fine' do
  post '/endpoint', params: params, headers: { 'Content-Type' => 'foo' }

  expect(response).to match_some_whatever
end

it 'is also fine I guess' do
  post '/endpoint', params: params

  expect(response).to match_some_whatever
end

Tests do a better job of ensuring the thing works, otherwise you gotta check everything in Postman whenever you change stuff. 测试可以更好地确保工作正常,否则无论何时更改东西,都要检查Postman中的所有内容。 That takes time, is unrealistic, and is going to lead to you pushing production issues regularly. 这需要时间,这是不现实的,并且会导致您定期推动生产问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在PHP中获取请求的“Content-Type”标头 - Get “Content-Type” header of request in PHP GET请求标头中的内容类型 - Content-type in a GET request header 使用 C# HttpClient 发送的 HEAD 请求返回的 Content-Type 不正确; 但是,邮递员返回正确的 Content-Type - Content-Type returned by HEAD request sent using C# HttpClient is incorrect; however, Postman returns the correct Content-Type 邮递员API无效的内容类型标题 - Postman API Invalid Content-Type Header 在WinRT HttpClient上设置请求Content-Type - Set request Content-Type on WinRT HttpClient 内容类型正确的HTTP GET请求未达到预期的服务方法 - HTTP GET request with proper content-type is not hitting the expected service method 如何使用HttpClient在(HTTP GET)Rest请求头集合中添加'Content-Type'头? - how to add 'Content-Type' header in (HTTP GET) Rest request header collection using HttpClient? GET请求上的Content-Type标头是否具有惯常的语义含义? - Does a Content-Type header on a GET request ever cary semantic meaning? 带有Content-Type的GET Request和带有JAX-RS Jersey 2.2的Accept标头 - GET Request with Content-Type and Accept header with JAX-RS Jersey 2.2 如何通过firefox插件RESTClient更改GET-Request的Content-Type - How to change Content-Type of GET-Request via firefox addon RESTClient
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM