2

I'm using request.js for http request in Node.js.

request({
  method: 'POST',
  uri: 'http://www.example.com/getData',
  followAllRedirects: true,
  followOriginalHttpMethod: true,
  json: true,
  form: {
    id: 1,
    msg: 'Test data',
  },
}, (err, res, body) => {})

Let's say when I post { id: 1, msg: 'Test data' } to http://www.example.com/getData, proxy will redirect to http://us.example.com/getData.

The codes above do redirect to http://us.example.com/getData, but How can I set the redirection with post data?

L_K
  • 2,838
  • 2
  • 16
  • 36

1 Answers1

0

This will be hard to do if not impossible.

If the redirects are done by sending "301 Moved Permanently" or "302 Found" HTTP status code then in practice it works as if it the "303 See Other" was sent, i.e. a GET request is made with no data sent in the body.

See List of HTTP status codes on Wikipedia:

This is an example of industry practice contradicting the standard. The HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented 302 with the functionality of a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish between the two behaviours. However, some Web applications and frameworks use the 302 status code as if it were the 303.

There is a "307 Temporary Redirect" (since HTTP/1.1) created to address this issue that is not allowed to change the HTTP method - so a redirect from POST should still be POST - see Wikipedia:

In this case, the request should be repeated with another URI; however, future requests should still use the original URI. In contrast to how 302 was historically implemented, the request method is not allowed to be changed when reissuing the original request. For example, a POST request should be repeated using another POST request.

But if that would work in that particular case is hard to tell as it depends on the API that you're calling and would require changes to that API implementation.

rsp
  • 107,747
  • 29
  • 201
  • 177
  • So the standard does not require post redirects to be sent with original post data? – L_K Apr 17 '17 at 01:55