Web service and redirection

Anthony Lucia
Anthony Lucia used Ask the Experts™
on
Lets say I write a web service,where that is a HTTP request / response service

Within that service, I want to have the browser that called me be redirected to another site.  

How can I perform that , what would that look like?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2015

Commented:
What does the web service return? HTML? Anything?
Jaime OlivaresSoftware Architect
Top Expert 2008
Commented:
your web service should return some data (xml, json, etc.). You can redirect the data location with a HTTP header, but that won't force the calling client to redirect to a different site.
In Java you generally call a "sendRedirect" method in the the servlet that is responding to the request:
http://www.javatpoint.com/sendRedirect()-method

This causes the user's browser to redirect to the new URL.  Other frameworks/languages should offer something similar.

If you're asking more deeply how this actually triggers the browser to do the redirect, I think it's by sending a response code that indicates that the URL has temporarily changed location.  If memory serves that's status code 307 (it'll be in the 300s - they're for moved/redirected resources) - anyway it's part of the HTTP spec.

Hope that helps,

Doug

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial