【问题标题】:macOS Paw - Parse response cookies for request headermacOS Paw - 解析请求标头的响应 cookie
【发布时间】:2019-02-13 17:52:11
【问题描述】:

如何解析响应 cookie 并将特定值发送回请求标头?

我正在发出请求:它在会话 cookie (token=longstrong) 中发回一个令牌。我需要获取该 cookie,解析出 token,然后将 x-token: 请求标头中的值发回以供后续请求使用。

Paw 只给了我发送 cookie(原始)的选项。

如何解析响应 cookie 以发回 $.token(json 伪代码)的

【问题讨论】:

    标签: cookies httpresponse paw-app


    【解决方案1】:

    回复晚了,抱歉!

    这可能会有所帮助(来自How do i pick specific cookies?):

    使用 Custom 动态值(右键单击该字段,然后选择 Extensions > Custom),并使用以下 JavaScript代码sn-p:

    function evaluate(context){
      // Set here the cookies you'd like to return
      var wantedCookies = ["datr", "reg_fb_ref"];
    
      var regex = /^(\w+)\=([^;\s]+)/g;
    
      // Request
      // Uses here the current request, you can use getRequestByName("name of the request") instead
      var request = context.getCurrentRequest();
    
      // Get response cookies
      var cookies = request.getLastExchange().getResponseHeaderByName("Set-Cookie").split(", ");
      var filteredCookies = [];
    
      for (var i in cookies) {
        var cookie = cookies[i];
        var match = regex.exec(cookie);
        if (match && wantedCookies.indexOf(match[1]) >= 0) {
          filteredCookies.push(match[0]);
        }
      }
    
      return filteredCookies.join(",");
    };
    

    这基本上是手动解析响应 cookie,并返回您需要的。


    这个其他问题可能会有所帮助:Routes using cookie authentication from previous version of Paw no longer work on new version

    【讨论】:

    • 完美!通过对我的要求进行一些调整,这正是我所需要的。谢谢,米查。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-13
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多