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.

For this purpose I use Postman. However, when I uncheck "Content-type" header in "Headers" tab Postman still sends Content-type=text/plain;charset=UTF-8.

Is there a way to avoid this and just not send anything in Content-type header?

Would appreciate any help, thanks

2 answers

  • answered 2018-01-11 21:27 Yuli Bonner

    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. enter image description here

  • answered 2018-01-11 23:10 Phil Sturgeon

    There are two worrying things here.

    so that it sets Content-type to application/json

    Are you saying you want request bodies to be interpreted as JSON even if they do not specify it as 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? 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.

    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. That takes time, is unrealistic, and is going to lead to you pushing production issues regularly.