Add header to every request in Postman in pre-request script

前端 未结 7 2084
春和景丽
春和景丽 2021-02-05 07:00

I want to automatically add a header to every request in my whole collection using this pre-request script:

pm.request.headers.add({
    \'key\': \"myvar\",
             


        
7条回答
  •  南方客
    南方客 (楼主)
    2021-02-05 07:52

    I think may be you can try this way :

      // Add or update an existing header
    
     pm.request.headers.upsert({
     'key': "myvar",
     'value': pm.environment.get("myvar") 
     });
    

    This was updated in Postman App (v7.0.9). For more reference you can refer to : https://github.com/postmanlabs/postman-app-support/issues/1947

提交回复
热议问题