How to get at authorization cookie programmatically?Does a finally block always get executed in Java?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How to get an enum value from a string value in Java?HTTP GET with request bodyHow do I set/unset a cookie with jQuery?Local Storage vs CookiesHow do I convert a String to an int in Java?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?Why is it common to put CSRF prevention tokens in cookies?

Company looks for long-term employees, but I know I won't be interested in staying long

Is encryption still applied if you ignore the SSL certificate warning for self signed?

How to not confuse readers with simultaneous events?

"Je suis petite, moi?", purpose of the "moi"?

How can I duct through a new cabinet from a floor vent opening at the wall?

Should I have one hand on throttle during engine ignition?

Last-minute canceled work-trip mean I'll lose thousands of dollars on planned vacation

What are the basics of commands in Minecraft Java Edition?

I have found a mistake on someone's code published online: what is the protocol?

Random piece of plastic

Why do space operations use "nominal" to mean "working correctly"?

How slow can a car engine run?

Is it legal for a supermarket to refuse to sell an adult beer if an adult with them doesn’t have their ID?

Zhora asks Deckard: "Are you for real?" Was this meant to be significant?

What causes a rotating object to rotate forever without external force—inertia, or something else?

Is surviving this (blood loss) scenario possible?

How much water can a ship take on before sinking?

Term “console” in game consoles

Operation Unzalgo

What would be the safest way to drop thousands of small, hard objects from a typical, high wing, GA airplane?

Obtaining head and parts without evaluation

Why can't I hear fret buzz through the amp?

Software need db owner permission to master database (sql2016)

What could make large expeditions ineffective for exploring territory full of dangers and valuable resources?



How to get at authorization cookie programmatically?


Does a finally block always get executed in Java?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?How to get an enum value from a string value in Java?HTTP GET with request bodyHow do I set/unset a cookie with jQuery?Local Storage vs CookiesHow do I convert a String to an int in Java?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?Why is it common to put CSRF prevention tokens in cookies?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have to implement an upload of a document to an archiving system via REST-interface using Java with spring boot.



I was told to make a GET request with Basic Authentication first. This will give me the authorization-cookies in the response. Then I have to send these cookies with the POST-request to do the actual archiving.



The GET works fine.
I read on the internet that I should get cookies in the "Set-Cookie" - header of the response.
But I get no cookies.



The strange thing is that if I execute the request with Postman, I get 2 cookies ("AuthSessionId" and "ClientId").
Why don't I get these programmatically?



As a sidenote: Postman also shows that I got 15 (other?) headers in the response. I have no problems finding these in my ClientHttpResponse



Here is some code:



ClientHttpResponse response = request.execute();
// this is org.springframework.http.client.ClientHttpResponse

List<String> cookies = response.getHeaders().get(HttpHeaders.SET_COOKIE);

if (cookies != null)
for (String cook : cookies)
System.out.println("cookie: " + cook);

else
System.out.println("no cookie in " + HttpHeaders.SET_COOKIE); // this is what I get










share|improve this question






















  • How do you build the request factory? For example, if you're using Apache's HttpClient implementation, it intercepts cookies headers and removes them, keeping them in a cookies store instead, which Spring's http interfaces don't expose. In that case you'd be better off using Apache HttpClient classes themselves and reading up on how to access cookies doing that.

    – kumesana
    Mar 26 at 10:21

















0















I have to implement an upload of a document to an archiving system via REST-interface using Java with spring boot.



I was told to make a GET request with Basic Authentication first. This will give me the authorization-cookies in the response. Then I have to send these cookies with the POST-request to do the actual archiving.



The GET works fine.
I read on the internet that I should get cookies in the "Set-Cookie" - header of the response.
But I get no cookies.



The strange thing is that if I execute the request with Postman, I get 2 cookies ("AuthSessionId" and "ClientId").
Why don't I get these programmatically?



As a sidenote: Postman also shows that I got 15 (other?) headers in the response. I have no problems finding these in my ClientHttpResponse



Here is some code:



ClientHttpResponse response = request.execute();
// this is org.springframework.http.client.ClientHttpResponse

List<String> cookies = response.getHeaders().get(HttpHeaders.SET_COOKIE);

if (cookies != null)
for (String cook : cookies)
System.out.println("cookie: " + cook);

else
System.out.println("no cookie in " + HttpHeaders.SET_COOKIE); // this is what I get










share|improve this question






















  • How do you build the request factory? For example, if you're using Apache's HttpClient implementation, it intercepts cookies headers and removes them, keeping them in a cookies store instead, which Spring's http interfaces don't expose. In that case you'd be better off using Apache HttpClient classes themselves and reading up on how to access cookies doing that.

    – kumesana
    Mar 26 at 10:21













0












0








0








I have to implement an upload of a document to an archiving system via REST-interface using Java with spring boot.



I was told to make a GET request with Basic Authentication first. This will give me the authorization-cookies in the response. Then I have to send these cookies with the POST-request to do the actual archiving.



The GET works fine.
I read on the internet that I should get cookies in the "Set-Cookie" - header of the response.
But I get no cookies.



The strange thing is that if I execute the request with Postman, I get 2 cookies ("AuthSessionId" and "ClientId").
Why don't I get these programmatically?



As a sidenote: Postman also shows that I got 15 (other?) headers in the response. I have no problems finding these in my ClientHttpResponse



Here is some code:



ClientHttpResponse response = request.execute();
// this is org.springframework.http.client.ClientHttpResponse

List<String> cookies = response.getHeaders().get(HttpHeaders.SET_COOKIE);

if (cookies != null)
for (String cook : cookies)
System.out.println("cookie: " + cook);

else
System.out.println("no cookie in " + HttpHeaders.SET_COOKIE); // this is what I get










share|improve this question














I have to implement an upload of a document to an archiving system via REST-interface using Java with spring boot.



I was told to make a GET request with Basic Authentication first. This will give me the authorization-cookies in the response. Then I have to send these cookies with the POST-request to do the actual archiving.



The GET works fine.
I read on the internet that I should get cookies in the "Set-Cookie" - header of the response.
But I get no cookies.



The strange thing is that if I execute the request with Postman, I get 2 cookies ("AuthSessionId" and "ClientId").
Why don't I get these programmatically?



As a sidenote: Postman also shows that I got 15 (other?) headers in the response. I have no problems finding these in my ClientHttpResponse



Here is some code:



ClientHttpResponse response = request.execute();
// this is org.springframework.http.client.ClientHttpResponse

List<String> cookies = response.getHeaders().get(HttpHeaders.SET_COOKIE);

if (cookies != null)
for (String cook : cookies)
System.out.println("cookie: " + cook);

else
System.out.println("no cookie in " + HttpHeaders.SET_COOKIE); // this is what I get







java rest cookies






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 9:55









scrxxscrxx

1




1












  • How do you build the request factory? For example, if you're using Apache's HttpClient implementation, it intercepts cookies headers and removes them, keeping them in a cookies store instead, which Spring's http interfaces don't expose. In that case you'd be better off using Apache HttpClient classes themselves and reading up on how to access cookies doing that.

    – kumesana
    Mar 26 at 10:21

















  • How do you build the request factory? For example, if you're using Apache's HttpClient implementation, it intercepts cookies headers and removes them, keeping them in a cookies store instead, which Spring's http interfaces don't expose. In that case you'd be better off using Apache HttpClient classes themselves and reading up on how to access cookies doing that.

    – kumesana
    Mar 26 at 10:21
















How do you build the request factory? For example, if you're using Apache's HttpClient implementation, it intercepts cookies headers and removes them, keeping them in a cookies store instead, which Spring's http interfaces don't expose. In that case you'd be better off using Apache HttpClient classes themselves and reading up on how to access cookies doing that.

– kumesana
Mar 26 at 10:21





How do you build the request factory? For example, if you're using Apache's HttpClient implementation, it intercepts cookies headers and removes them, keeping them in a cookies store instead, which Spring's http interfaces don't expose. In that case you'd be better off using Apache HttpClient classes themselves and reading up on how to access cookies doing that.

– kumesana
Mar 26 at 10:21












1 Answer
1






active

oldest

votes


















0














kumesana is right. The cookies are filtered out and put into a CookieStore. If I set this before, I can fetch them after the request is finished:



CookieStore cookieStore = new BasicCookieStore();
CloseableHttpClient client = HttpClientBuilder
.create()
.setDefaultCredentialsProvider(credentialsProvider)
.setConnectionManager(poolingConnectionManager)
.setDefaultCookieStore(cookieStore)
.build();





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354205%2fhow-to-get-at-authorization-cookie-programmatically%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    kumesana is right. The cookies are filtered out and put into a CookieStore. If I set this before, I can fetch them after the request is finished:



    CookieStore cookieStore = new BasicCookieStore();
    CloseableHttpClient client = HttpClientBuilder
    .create()
    .setDefaultCredentialsProvider(credentialsProvider)
    .setConnectionManager(poolingConnectionManager)
    .setDefaultCookieStore(cookieStore)
    .build();





    share|improve this answer



























      0














      kumesana is right. The cookies are filtered out and put into a CookieStore. If I set this before, I can fetch them after the request is finished:



      CookieStore cookieStore = new BasicCookieStore();
      CloseableHttpClient client = HttpClientBuilder
      .create()
      .setDefaultCredentialsProvider(credentialsProvider)
      .setConnectionManager(poolingConnectionManager)
      .setDefaultCookieStore(cookieStore)
      .build();





      share|improve this answer

























        0












        0








        0







        kumesana is right. The cookies are filtered out and put into a CookieStore. If I set this before, I can fetch them after the request is finished:



        CookieStore cookieStore = new BasicCookieStore();
        CloseableHttpClient client = HttpClientBuilder
        .create()
        .setDefaultCredentialsProvider(credentialsProvider)
        .setConnectionManager(poolingConnectionManager)
        .setDefaultCookieStore(cookieStore)
        .build();





        share|improve this answer













        kumesana is right. The cookies are filtered out and put into a CookieStore. If I set this before, I can fetch them after the request is finished:



        CookieStore cookieStore = new BasicCookieStore();
        CloseableHttpClient client = HttpClientBuilder
        .create()
        .setDefaultCredentialsProvider(credentialsProvider)
        .setConnectionManager(poolingConnectionManager)
        .setDefaultCookieStore(cookieStore)
        .build();






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 14:41









        scrxxscrxx

        1




        1
















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55354205%2fhow-to-get-at-authorization-cookie-programmatically%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript