-1

I have the following cUrl command to send reqest to server

curl -k https://localhost:9200 -H "Authorization: Bearer eH8AIFX6PqyrmJ1cJLC"

in the server side I need to retrieve the token that is eH8AIFX6PqyrmJ1cJLC.

the line,

String access_token=request.header("Authorization: Bearer");

outputs : Bearer eH8AIFX6PqyrmJ1cJLC

But I only want to retrieve eH8AIFX6PqyrmJ1cJLC.

How do I do this.

Thanks.

Radha
  • 61
  • 1
  • 10

2 Answers2

1

You could use String.split() to split the value at the space character and then use the second part.

Or you could just discard the first 7 characters if you know that it will always be "Bearer".

Or you could use String.replace() to replace "Bearer " with "".

Jason
  • 11,744
  • 3
  • 42
  • 46
0

In general, either the Framework or the http classes you are using should provide a way to get the headers. If the output is not in your wanted format, just parse the output. In your case you could use e.g. access_token.replace("Bearer ", "").

Marvin Klar
  • 1,869
  • 3
  • 14
  • 32