I'm sending an HTTP POST request to a URL. It sends back a piece of information I need in the location header of the response. How do I get that header? I've tried the following code and it doesn't seem to work:
In the action block of the rule that uses the http:post() action:
http:post("https://cas.byu.edu/cas/v1/tickets/")
with params = {"username": netid, "password": password}
and autoraise = "gottgt"
and response_headers = ["location"];
The rule that handles the http event:
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;
}
}
However, the location variable is always blank. How do I tell KRL that I want the location header, and how do I get it from the response?
While I can't test your specific endpoint, I've built a sample app that you will find useful in debugging this issue.
Note that I'm both autoraising the response, and using the
settingsyntax to raise the events. You wouldn't normally do both, but it hilights a difference. When explicitly raising the result, you get the entire response. You can see in my example that theserverheader is returned, and shown also in the autoraised rule.Your code looks right, but I'd do an explicit raise and inspect the response as I show here, and that will help you know exactly what is available to you.
Run this app here: http://ktest.heroku.com/a8x183
and code here: