POST数据并通过PHP CURL重定向用户 [英] POST data and redirect user by PHP CURL

查看:214
本文介绍了POST数据并通过PHP CURL重定向用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要使用PHP CURL将用户重定向到URL并将一些数据发送到该URL(POST).就像用户单击HTML表单时使用POST方法提交一样.

We need to redirect users to a URL and send some data to that URL (POST) with PHP CURL. Exactly like when a user click on HTML form submit with POST method.

我们的代码是

$data=array("Token"=>"test2","RedirectURL"=>"test1");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sep.shaparak.ir/Payment.aspx');  
curl_setopt($ch, CURLOPT_REFERER, 'https://sep.shaparak.ir/Payment.aspx'); 
curl_setopt($ch, CURLOPT_HEADER, false);  
curl_setopt($ch, CURLOPT_POST, 1);  
curl_setopt($ch, CURLOPT_VERBOSE, false);  
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);  
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);  
curl_setopt($ch, CURLOPT_POSTREDIR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);  
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_exec($ch);

但这是行不通的.

解决方案是什么?

推荐答案

我发现,仅使用PHP是不可能的.

As I found, it is not possible just with PHP.

您可以使用PHP生成表单,然后在onLoad中使用JS提交表单.

You can generate a form with PHP and submit that with JS in onLoad.

此处更为详细.

这篇关于POST数据并通过PHP CURL重定向用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆