Sending Cookie info in HttpRequest

前端 未结 5 1498
抹茶落季
抹茶落季 2020-12-10 20:11

I want to call a web service that requires an authentication cookie.

I have the cookie name and value. but I don\'t know how to inject the cookie in the request.

5条回答
  •  时光取名叫无心
    2020-12-10 20:47

    You can use droidQuery to handle the request:

    $.ajax(new AjaxOptions().url("http://www.example.com")
                            .type("POST")
                            .dataType("json")
                            .data("data to post")
                            .cookies($.map($.entry("key", "value"))));
    

    droidQuery also has authentication built in using the standard HTTP authentication approach:

    $.ajax(new AjaxOptions().url("http://www.example.com")
                            .type("POST")
                            .dataType("json")
                            .data("data to post")
                            .username("myusername")
                            .password("myPassword"));
    

提交回复
热议问题