Ok, so in my web app's API I have an incoming HTTP post request. I would like to pass that POST request on to a different server, without losing the data in the POST header. Is this possible? which type of redirect would I use? php examples?
Edit: The HTTP request is coming from a mobile app, not a web browser.
Thanks!
The P on there (proxy) will preserve the POST data. You'll need to turn on the apache proxy module if it isn't already.
You cannot tell a browser to make a post request through an HTTP header. The
location
header will redirect, but only for GET or HEAD requests.You can work around this limitation by displaying a page with a hidden form with the method attribute set to POST and the action set to the URL you want the browser to post to, then automatically submit it on page load. Example:
Alternately, you can make the POST request on your server and then display the results.
If you want to take data from a POST request and simply POST it to another server, then use cURL.
--or--
If you want to take data from a POST request and redirect the client to that other server while POSTing the data, then use this method...
Dynamically generate a form with all of the POST data. Something likes this...
Then, submit that form with some JavaScript when the page is done loading...
I used the following code to redirect a post. In my case I am using only application/octet-stream content type so make sure you take that into consideration.
You could use cURL or sockets to re-post the data, but you can't really redirect it.
POST'ing to a URL with cURL:
If the client (ie the mobile app) HTTP library supports this, then you can return HTTP 307 from server which states that "the request should be repeated with another URI ... with the same method". This is essentially a temporary redirect but tells the client to use the the same method, a POST.
The client making the request must be able to respond accordingly to the HTTP 307 response and follow the redirection with the same method - for many libraries this may be an additional flag or setting.