How to delete session cookie in Postman?

后端 未结 12 1427
渐次进展
渐次进展 2020-12-05 01:18

I am testing my API in Postman and am having trouble simulating a log out.

If I do a call to delete the session cookie,

12条回答
  •  心在旅途
    2020-12-05 02:10

    new version of postman app has the ability to do that programmatically in pre-request or tests scripts since 2019/08

    see more examples here: Delete cookies programmatically · Issue #3312 · postmanlabs/postman-app-support

    clear all cookies

    const jar = pm.cookies.jar();
    
    jar.clear(pm.request.url, function (error) {
      // error - 
    });
    

    get all cookies

    const jar = pm.cookies.jar();
    
    jar.getAll('http://example.com', function (error, cookies) {
      // error - 
      // cookies - 
      // PostmanCookieList: https://www.postmanlabs.com/postman-collection/CookieList.html
    });
    

    get specific cookie

    const jar = pm.cookies.jar();
    
    jar.get('http://example.com', 'token', function (error, value) {
      // error - 
      // value - 
    });
    

提交回复
热议问题