droidQuery icon indicating copy to clipboard operation
droidQuery copied to clipboard

Are there any examples showing how to use the .headers option for a GET request?

Open alexf1 opened this issue 9 years ago • 2 comments

trying to find documentation that shows how to format headers when doing GET request

alexf1 avatar Mar 08 '16 20:03 alexf1

There's not much documentation other than the javadocs for Header.java. When constructing your AjaxOptions object, you need to pass the headers to it, and you can create those headers using any of the available methods. If you use a String, this should be formatted like JSON - for example:

AjaxOptions options = new AjaxOptions().headers(new Headers("{\"Accept\":\"application/json\"}"));

You might be able to get away without using the escaped quotation marks:

AjaxOptions options = new AjaxOptions().headers(new Headers("{Accept:application/json}"));

To add additional ones, just add a comma:

{Accept:application/json,Content-Type:application/json}

You can also pass a Map Object, an array of Header objects, or a JSONObject.

phil-brown avatar Mar 08 '16 23:03 phil-brown

I did something like this

    Headers header =  new Headers();
    header.add("X-SESSION-KEY",sessionkey);
    header.add("X-GLOBAL-KEY", globalKey);

and then .headers(header)

If it doesn't work I'll try the methods you have and see if that works. Thanks Phil

alexf1 avatar Mar 09 '16 14:03 alexf1