当post的请求需要301或者302这么携带post的数据呢
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了当post的请求需要301或者302这么携带post的数据呢,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3080字,纯文字阅读大概需要5分钟。
内容图文
![当post的请求需要301或者302这么携带post的数据呢](/upload/InfoBanner/zyjiaocheng/152/c13af97440a24273949c334d70d64daa.jpg)
问题:因为我是已有程序迁移到slim框架上,所以,真对以前的动态地址做了withRedirect,代码如下:
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 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('act');
$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['act']);
$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
而很多一些异步请求为post,301到新的地址后,直接丢失了post的数据,如图:
我记得重定向是可以携带post数据的,但是在slim中,这么从Response设置呢?请教!
感谢?!
回复内容:
问题:因为我是已有程序迁移到slim框架上,所以,真对以前的动态地址做了withRedirect,代码如下:
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 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('act');
$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['act']);
$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
而很多一些异步请求为post,301到新的地址后,直接丢失了post的数据,如图:
我记得重定向是可以携带post数据的,但是在slim中,这么从Response设置呢?请教!
感谢?!
没看明白,但是30X代表的应该就是服务器重定向吧,这个状态码是服务器response回来的应该是无疑的。php可以通过header函数来设置。
首先这些参数应该在301之前处理还是之后处理,好的设计应该是在301之前处理,处理完之后做个重定向,展示相关的结果页面,只带上必要的查询参数,这时不应该再去取POST参数了,而是直接根据查询参数展示结果。
内容总结
以上是互联网集市为您收集整理的当post的请求需要301或者302这么携带post的数据呢全部内容,希望文章能够帮你解决当post的请求需要301或者302这么携带post的数据呢所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。