简体   繁体   English

如何在php中重定向/转发请求?

[英]How to redirect/forward request in php?

I use httpful to send http request and get the response to display in request.php 我使用httpful发送http请求并获取响应以显示在request.php中

include('httpful.phar');

$response = \Httpful\Request::get('http://domain/response.php')->send();

echo '<textarea rows="20" cols="100">';
echo $response;
echo '</textarea>';

In response.php, I use header to redirect the request to another page, but I cannot get the expected response. 在response.php中,我使用标头将请求重定向到另一个页面,但无法获得预期的响应。

header("HTTP/1.1 301 Moved Permanently");
header("Location:http://otherdomain/other_response.php");

echo 'internal response page'

I have also tried 我也尝试过

header("HTTP/1.1 302 Found");

but it still only get the response 'internal response page' 但它仍然只获得响应“内部响应页面”

what is the correct way to redirect/forward the request to other_response.php? 将请求重定向/转发到other_response.php的正确方法是什么?

From what I know, you may only use header(); 据我所知,您只能使用header(); once. 一旦。 And it has to output before anything else. 它必须先输出。 From the code that you showed, I don't see any mistakes besides that. 根据您显示的代码,除此之外,我看不到任何错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM