Redirecting get to post?

5,207 views
Skip to first unread message

Randall Bennett

unread,
Feb 2, 2012, 3:42:25 PM2/2/12
to expre...@googlegroups.com
Hey guys,

So I'm dealing with a sitch where I have a device that can only generate a get request. Ideally, I'd like to redirect it to a post method. Using res.redirect, is there a way to do that?

Thanks,
rb

Ryan Schmidt

unread,
Feb 2, 2012, 4:18:46 PM2/2/12
to expre...@googlegroups.com

On Feb 2, 2012, at 14:42, Randall Bennett wrote:

> So I'm dealing with a sitch where I have a device that can only generate a get request. Ideally, I'd like to redirect it to a post method. Using res.redirect, is there a way to do that?

No, and it's not a deficiency of express or node; rather, the HTTP specification doesn't really accommodate that usage.

http://stackoverflow.com/questions/46582/response-redirect-with-post-instead-of-get

The client itself must generate the POST request.

Also, you do understand what a redirect is, right? If I issue an HTTP GET request for http://nodejs.org/docs I receive the following response:

$ curl -I http://nodejs.org/docs
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Thu, 02 Feb 2012 21:15:02 GMT
Content-Type: text/html
Content-Length: 178
Location: http://nodejs.org/docs/
Connection: keep-alive

The server has issued a redirect: that is, it is telling my user agent "Please issue a new request for http://nodejs.org/docs/". I then have to issue that new request if I want to see the document.

Why do you think you need a POST request? Is this POST request to your node.js application, or to somebody else's server? If it's to your own app, rewrite your app to accept a GET request instead. If it's to someone else's server, write your own wrapper server which will accept a GET request, send a corresponding POST request to the foreign server, receive the result, and send it back to the client.


Randall Bennett

unread,
Feb 2, 2012, 6:09:26 PM2/2/12
to expre...@googlegroups.com
Yeah... I guess i was living in express land and didn't think of res.redirect as actually doing a "real" redirect for some reason.

I've got other good methods that feel less pure, so I'll be ok.

rb



--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.


Sebastian Lasse

unread,
Mar 8, 2014, 6:24:13 AM3/8/14
to expre...@googlegroups.com

HTTP 1.1 spec DOES accommodate this usage, it is called Post-Redirect-Get, human readable explanation:
Reply all
Reply to author
Forward
0 new messages