我希望通过向其发送一些POST参数来从URL http://webcache.gmc-uk.org/gmclrmp_enu/start.swe获得响应。 我写了一个函数如下:
public function getResponse($params, $url)
{
$post_data = '';
foreach ($params as $key => $value) {
$post_data .= $key . '=' . $value . '&';
}
//create the final string to be posted using implode()
$post_data = rtrim($post_data, '&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, count($post_data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
但是,当我将此函数称为:
public function getIndex()
{
$params = array(
"s_3_1_5_0" => "5205500"
);
$url = 'http://webcache.gmc-uk.org/gmclrmp_enu/start.swe';
echo $this->getResponse($params, $url);
}
我总是被重定向到页面:http://localhost:8000/gmclrmp_enu/start.swe 而不是从指定的URL获取响应。 其中,http:// localhost:8000 /是我本地项目的根URL。
我如何从该URL获取响应并将其转储?
答案 0 :(得分:0)
我尝试了你的代码并得到了这个回复。
<html>
<body>
<form action="/gmclrmp_enu/start.swe" method="POST" name="RedirectForHost">
<input type = "hidden" name="s_3_1_5_0" value="5205500">
<input type = "hidden" name="SWEBHWND" value="">
<input type = "hidden" name="_sn" value="QG3N3byeQ-lw2X0470Taoo2Mr1xU6fklSaK4bX.yXOH1DqcEpmRHVzctRxa1UYflcu-svwV7M0VFB6KvWmUEh4mUDGbJtaXeil1PnikFKVpr6fRP.i-GMhMRm41kZVFHaZA1QBjteOlfTXcwF0CLSh.MzwHUhdPVvYK9Ulfe.zCJQiSkU2XOt68YjT1lD-4jrTrIBzxJLUY_">
<input type = "hidden" name="SRN" value="">
<input type = "hidden" name="SWEHo" value="">
<input type = "hidden" name="SWETS" value="1481276787">
</form>
<script language="javascript">
var formObj = document.forms["RedirectForHost"];
formObj.SWEHo.value=top.location.hostname;
formObj.submit();
</script>
</body>
</html>
我认为你得到了这样的回复,然后javascript将表单提交给localhost:8000。