php 如何将POST数据发送到外部url并打开目标url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17994108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send POST data to external url and open the target url
提问by bbbb
I want to send the POST data to the given external url like http://www.example.com/catchPostData.php, where the catchPostData.php looks like this:
我想将 POST 数据发送到给定的外部 url,如http://www.example.com/catchPostData.php,其中 catchPostData.php 如下所示:
<?php
echo $_POST['somedata'];
?>
and open this url with the data I've send.
并用我发送的数据打开这个网址。
I've tryed to use cURL, but it returns from the given url, and I want to stay there!
我尝试使用 cURL,但它从给定的 url 返回,我想留在那里!
Can anybody help me with this?
有人可以帮我解决这个问题吗?
采纳答案by Wesley Overdijk
I think you're looking for something like this: PHP Redirect with POST data
我想你正在寻找这样的东西:PHP Redirect with POST data
You will need a second page, that submits the post data to a completely different url.
您将需要第二个页面,将帖子数据提交到一个完全不同的 url。
回答by awsmketchup
You will need two pages: one page for the input, the second page which redirects the input to an external url. as such your code would look like this:
您将需要两页:一页用于输入,第二页将输入重定向到外部 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");
回答by Napster
You can use with document.ready function
您可以使用 document.ready 功能
$.post({
url: "you_page.php",
type: "POST",
data:{formId:form_id},
success: function (data){
}
});