What if post requests require 301 or 302 to carry post data?

Source: Internet
Author: User
Problem: Because I migrate an existing program to the slim framework, withRedirect has been implemented for the previous dynamic address. the code is as follows: {code ...} while many asynchronous requests are post, and after 301 to the new address, the post data is directly lost. I remember that redirection can carry...

Problem: Because I migrate an existing program to the slim framework, we have done withRedirect for the previous dynamic address. the code is as follows:


  Ci = $ ci;}/*** Compatible URL middleware invokable class. ** @ param \ Psr \ Http \ Message \ RequestInterface $ request PSR7 request * @ param \ Psr \ Http \ Message \ ResponseInterface $ response PSR7 response * @ param callable $ next middleware * @ return \ Psr \ Http \ Message \ ResponseInterface * @ author Seven Du
  
   
**/Public function _ invoke (Request $ request, Response $ response, callable $ next) {$ app = $ request-> getQueryParam ('app '); $ mod = $ request-> getQueryParam ('mod'); $ act = $ request-> getQueryParam ('AC'); $ param = []; if ($ app! = Null) {$ param ['app'] = $ app;} if ($ mod! = Null) {$ param ['controller'] = $ mod;} if ($ act! = Null) {$ param ['action'] = $ act;} $ router = $ this-> ci-> get ('router '); $ queryParam = $ request-> getQueryParams (); unset ($ queryParam ['app'], $ queryParam ['mod'], $ queryParam ['AC']); $ uri = $ router-> pathFor ('apps ', $ param, $ queryParam); if ($ uri! = $ Router-> pathFor ('apps ', [], $ queryParam )) {// permanently redirect paths with a trailing slash // to their non-trailing counterpart return $ response-> withRedirect (string) $ uri, 301 );} return $ next ($ request, $ response) ;}// END class CompatibleURL
  

However, many asynchronous requests are post, and after 301 to the new address, the post data is directly lost,

I remember that redirection can carry post data, but in slim, how do I set it from Response? Ask!
Thank you ?!

Reply content:

Problem: Because I migrate an existing program to the slim framework, we have done withRedirect for the previous dynamic address. the code is as follows:


  Ci = $ ci;}/*** Compatible URL middleware invokable class. ** @ param \ Psr \ Http \ Message \ RequestInterface $ request PSR7 request * @ param \ Psr \ Http \ Message \ ResponseInterface $ response PSR7 response * @ param callable $ next middleware * @ return \ Psr \ Http \ Message \ ResponseInterface * @ author Seven Du
  
   
**/Public function _ invoke (Request $ request, Response $ response, callable $ next) {$ app = $ request-> getQueryParam ('app '); $ mod = $ request-> getQueryParam ('mod'); $ act = $ request-> getQueryParam ('AC'); $ param = []; if ($ app! = Null) {$ param ['app'] = $ app;} if ($ mod! = Null) {$ param ['controller'] = $ mod;} if ($ act! = Null) {$ param ['action'] = $ act;} $ router = $ this-> ci-> get ('router '); $ queryParam = $ request-> getQueryParams (); unset ($ queryParam ['app'], $ queryParam ['mod'], $ queryParam ['AC']); $ uri = $ router-> pathFor ('apps ', $ param, $ queryParam); if ($ uri! = $ Router-> pathFor ('apps ', [], $ queryParam )) {// permanently redirect paths with a trailing slash // to their non-trailing counterpart return $ response-> withRedirect (string) $ uri, 301 );} return $ next ($ request, $ response) ;}// END class CompatibleURL
  

However, many asynchronous requests are post, and after 301 to the new address, the post data is directly lost,

I remember that redirection can carry post data, but in slim, how do I set it from Response? Ask!
Thank you ?!

I don't understand, but 30X indicates server redirection. This status code is returned by the server response. Php can be set through the header function.

First, these parameters should be processed before 301 or later. a good design should be done before 301. after processing, a redirection will be made to display the relevant results page, with only necessary query parameters, in this case, the POST parameter should not be retrieved, but the results should be displayed directly based on the query parameters.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.