我想将POST数据发送到给定的外部URL,如http://www.example.com/catchPostData.php,其中catchPostData.php如下所示:
<?php
echo $_POST['somedata'];
?>
并使用我发送的数据打开此网址。
我已尝试使用cURL,但它从给定的网址返回,我想留在那里!
有人可以帮我吗?
答案 0 :(得分:2)
我认为你正在寻找这样的事情:PHP Redirect with POST data
您需要第二页,将发布数据提交到完全不同的网址。
答案 1 :(得分:-2)
您将需要两个页面:一个页面用于输入,第二个页面将输入重定向到外部URL。因此,您的代码将如下所示:
page1:
<form method="post" action="./page2.php">
<input type="hidden" name="somedata" value="yourData">
<input type="submit" name="submit" />
</form>
page2:
//you can create an array contains your posted data
//if you are dealing with multiple values
$array = array("somedata"=>$_POST['somedata']);
//create a url variable that will store all values
//since you are going to send them as part of a single url
$url="";
//if you are posting more than one value you will need to loop
//through each one - not necessary if you are sending a single value
foreach($array as $key=>$value){
$url .=$key."=".urlencode($value)."&";
}
header("http://www.example.com/catchPostData.php?$url");
答案 2 :(得分:-3)
您可以使用document.ready function
$.post({
url: "you_page.php",
type: "POST",
data:{formId:form_id},
success: function (data){
}
});