Get Request Header in Restlet

When using Restlet library to invoke RESTful method, sometimes you need to parse the request header for further use. And luckily, though there is explicit ways to solve this problem, we can still get what we need.

Calling getRequestAttributes().get(”org.restlet.http.headers”); will return all the headers in the request. However, the type of returned result is “org.restlet.data.Form”. Consequently, we need to convert it into the Form format, and then using the getFirstValue(”") method to retrieve the value. One catch there is the key is always start with capital letter, for instant even is “location” in the header, you have to use “Location” instead.

Form headers = (Form) getRequestAttributes().get(”org.restlet.http.headers”);
location = headers.getFirstValue(”Location”);

This entry was posted on Sunday, December 13th, 2009 at 10:54 pm and is filed under Uncategorized . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Be the first to comment! Leave a Reply.

You must be logged in to post a comment.

  • Chinese Version

    • Wanna know me more? And you can read Chinese? Feel free to visit my Chinese site, more life records will be found there and wish you enjoying it.
  • Thanks for support

  • twitter

    facebook

    linkedin

  • Categories