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?
Multi tool use
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;
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
add a comment |
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
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
add a comment |
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
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
java rest cookies
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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();
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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();
add a comment |
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();
add a comment |
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();
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();
answered Mar 26 at 14:41
scrxxscrxx
1
1
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Jb,7,nt,iiMvSk,G5ZV2woXwpLQ
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