0
0
Postmantesting~10 mins

Request headers in Postman - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a custom header named 'Authorization' with value 'Bearer token123' in Postman.

Postman
pm.request.headers.add({ key: 'Authorization', value: '[1]' });
Drag options to blanks, or click blank then click option'
AAuth token
BToken 123
CBearer_token
DBearer token123
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect header value format like missing 'Bearer' keyword.
Using spaces or underscores incorrectly in the token string.
2fill in blank
medium

Complete the code to check if the request header 'Content-Type' is set to 'application/json' in Postman test script.

Postman
pm.test('Content-Type is JSON', () => { pm.expect(pm.request.headers.get('Content-Type')).to.eql('[1]'); });
Drag options to blanks, or click blank then click option'
Amultipart/form-data
Btext/html
Capplication/json
Dapplication/xml
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text/json' instead of 'application/json'.
Misspelling the header value.
3fill in blank
hard

Fix the error in the code to correctly set the 'Accept' header to 'application/xml' in Postman pre-request script.

Postman
pm.request.headers.upsert({ key: 'Accept', value: '[1]' });
Drag options to blanks, or click blank then click option'
Aapplication/json
Bapplication/xml
Ctext/plain
Dtext/html
Attempts:
3 left
💡 Hint
Common Mistakes
Setting 'Accept' header to 'application/json' when XML is expected.
Using incorrect MIME types like 'text/xml'.
4fill in blank
hard

Fill both blanks to add a header 'Cache-Control' with value 'no-cache' and verify it in a test script.

Postman
pm.request.headers.add({ key: '[1]', value: '[2]' });
pm.test('Cache-Control header is set', () => { pm.expect(pm.request.headers.get('Cache-Control')).to.eql('no-cache'); });
Drag options to blanks, or click blank then click option'
ACache-Control
Bno-cache
CCacheControl
Dno-store
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'CacheControl' without hyphen as header key.
Using 'no-store' instead of 'no-cache' as header value.
5fill in blank
hard

Fill all three blanks to create a test that checks if the 'User-Agent' header contains 'PostmanRuntime'.

Postman
pm.test('User-Agent contains PostmanRuntime', () => {
  const userAgent = pm.request.headers.get('[1]');
  pm.expect(userAgent).to.include('[2]');
  pm.expect(typeof userAgent).to.eql('[3]');
});
Drag options to blanks, or click blank then click option'
AUser-Agent
BPostmanRuntime
Cstring
Duser-agent
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'user-agent' which may not match the header key.
Checking for wrong substring in the header value.
Using wrong type in the typeof check.