cookies - macOS Paw - 解析请求 header 的响应 cookie

标签 cookies httpresponse paw-app

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

我正在发出请求:它会在 session cookie 中发回 token (token=longstrong)。我需要获取该 cookie,解析出 token,并在 x-token: 请求 header 中发回以下请求的值。

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

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

最佳答案

回复晚了,抱歉!

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

改用自定义动态值(右键单击该字段,然后选择扩展> 自定义),并使用以下 JavaScript代码片段:

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

关于cookies - macOS Paw - 解析请求 header 的响应 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54676504/

相关文章:

python - 为什么我无权使用 Python 在 Data Lake gen2 中创建文件系统

java - 响应 sendRedirect() 处理

paw-app - 有什么办法可以在 Paw 3 中显示 .paw 文件吗?

php - 如何在查询时区分管理员和用户?

php - 如何修复 MediaWiki 错误 "Wiki uses cookies to log in users. You have cookies disabled. Please enable them and try again."?

javascript - jQuery $.cookie 不是函数

c# - 使用 C# 的 HTTP 请求

paw-app - 如何从 *Paw for Teams* 解压 project.tar?

user-agent - 如何在 Paw 中设置自定义用户代理?

asp.net - 使用 JavaScript 读取 cookie