gpt4 book ai didi

php - 无法使用post请求将数据发送到服务器

转载 作者:搜寻专家 更新时间:2023-10-31 21:55:26 25 4
gpt4 key购买 nike

我有 2 个文件。

文件one.php:

<?php 
include 'config/dbconnect.php';
$query = mysql_query("select * from getgift_logs where status = 1") or die(mysql_error());
echo("<table border='1'>");
echo("<tr>");
echo("<td>User ID</td>");
echo("<td>Yes</td>");
echo("</tr>");
while ($row = mysql_fetch_array($query)) {
echo("<tr>");
echo("<td>".$row['user_id']."</td>");
echo "<td><button class='yes' gift_id = '".$row['id']."'>Yes</button></td>";
echo("</tr>");
}
echo("</table>");
?>
<div id='result'></div>
<script type = "text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$('.yes').click(function() {
var trans_id=$(this).attr("gift_id");
$.ajax({
url : "process.php?id="+trans_id,
type: "GET",
success: function(result) {
$('#result').html(result);
},
});
});
</script>

文件 one.php 我向 process.php 文件发送一个获取请求。这是文件 process.php:

<?php 
include("config/dbconnect.php");
date_default_timezone_set("UTC");
$id = $_POST['trans_id'];

$query = mysql_query("select * from getgift_logs where id = '".$id."'");

$row = mysql_fetch_array($query);
$topuplink = $row['topuplink'];
$trans_id = $row['trans_id'];
$clientsecret = $row['clientsecret'];
$accesstoken = $row['accesstoken'];
$lost_money = $row['lost_money'];
$status = $row['description'];
$time = date('Ymdhis',time());
$sign = md5($money."|".$trans_id."|".$time."|".$clientsecret);
$ch = curl_init();
$data = array(
'topup_money' => $lost_money,
'reference_trans_id' => $trans_id,
'description'=>$status,
'request_time'=> $time,
'sign'=>$sign
);

$postvars = '';
foreach($data as $key=>$value) {
$postvars .= $key . "=" . $value . "&";
}
$url = $topuplink."".$accesstoken;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
print_r($response);
curl_close ($ch);
?>

process.php 文件中,我发送了 POST REQUEST 但它不起作用(它不向服务器发送数据)。

我不知道我做错了什么?请帮我!谢谢大家!

最佳答案

试试这个

$postvars = '';
foreach($data as $key=>$value) {
$postvars .= $key . "=" . $value . "&";
}
rtrim($postvars , '&'); // remove last &

$url = $topuplink."".$accesstoken;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, count($data)); // count of total post fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $postvars);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
print_r($response);
curl_close ($ch);

关于php - 无法使用post请求将数据发送到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34460107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com