This week's book giveaway is in the Reactive Progamming forum. We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line! See this thread for details.
I am writing a client code that needs to access a Rest web service.But I need to send authentication details in header so that it can be retrieved from Request header in the web service code.
I am using Spring and JSP to write the client code. Any idea how can I do it?
Any help will be appreciated.Thanks.
You shouldn't have to set any headers. Just go ahead and make the request. If the RESTful web service needs basic authentication and is correctly written, it will return a 401 response which will trigger the browser to prompt you for credentials. Once you enter the credentials the browser will retry the request automatically with the appropriate header set.
If the web service ism't using HTTP correctly, or is not using HTTP authentication, you will not be able to submit requests to it using browser forms.
Solution that you posted will not be acceptable because in my case it will not work the way you have mentioned.My client code needs to pass an authentication token as an attribute of the request.If I do not pass that token,I will get a server side error message.
Bear you are right.Service is not using HTTP authentication.How do I make request using Java and set token in request header?
My client is a Spring controller so I think I may be able to write some additional code in that to set request header.
posted 8 years ago
Can someone please respond?
My main issue is setting request header .Can I even use filter to set request header considering that my code is a client code to a Rest Web service?If yes,how can I do that?