如何解决KRL:从http:post获取“位置”标头
|| 我正在将HTTP POST请求发送到URL。它在响应的“ 0”标头中发回一条我需要的信息。如何获得该标头?我尝试了以下代码,但似乎不起作用: 在使用“ 1”操作的规则的操作块中:http:post(\"https://cas.byu.edu/cas/v1/tickets/\")
with params = {\"username\": netid,\"password\": password}
and autoraise = \"gottgt\"
and response_headers = [\"location\"];
处理“ 3”事件的规则:
rule got_tgt {
select when http post label \"gottgt\"
pre {
content = event:param(\"content\");
location = event:param(\"location\");
}
{
notify(\"CAS Login\",\"Got back the POST response (#{location}): #{content}\") with sticky=true;
}
}
但是,变量“ 0”始终为空白。如何告诉KRL我想要location
标头,以及如何从响应中获取标头?
解决方法
虽然我无法测试您的特定端点,但是我构建了一个示例应用程序,您将发现它对于调试此问题很有用。
请注意,我既要自动提高响应,又要使用
setting
语法来引发事件。通常您不会同时执行这两种操作,但它带来了不同。当明确提出结果时,您将获得整个响应。您可以在我的示例中看到返回了server
标头,并且还显示在自动提高的规则中。
您的代码看起来不错,但是我将进行明确的加薪并检查我在此处显示的响应,这将帮助您确切地了解可用的内容。
在此处运行此应用程序:http://ktest.heroku.com/a8x183
和代码在这里:
ruleset a8x183 {
meta {
name \"Testing Response Headers\"
description <<
>>
author \"Sam Curren\"
logging off
}
dispatch {
// domain \"example.com\"
}
global {
bodylog = defaction(title,msg){
{
append(\"body\",\"<h1>#{title}</h1>\");
append(\"body\",\"<div>#{msg}</div>\");
}
};
}
rule first_rule {
select when pageview \".*\" setting ()
pre {
}
http:post(\"http://httpbin.org/post\") setting (res)
with params = {\"username\":\"yahuda\",\"password\":\"metalcages\"}
and autoraise = \"kickstand\"
and response_headers = [\"server\"];
fired {
raise explicit event \"moon\" with res = res;
}
}
rule exp {
select when explicit moon
pre {
res = event:param(\"res\");
res_s = res.encode();
}
bodylog(\"explicit raise: full response\",res_s);
}
rule response {
select when http post label \"kickstand\"
pre {
server_header = event:param(\"server\");
content = event:param(\"content\");
}
{
bodylog(\"autoraise: content\",content);
bodylog(\"autoraise: server_header\",server_header);
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。