[英]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-type
为application/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.