如何在php会话中发出post请求?
无法在会话中发出post请求,有人能帮忙吗?我从以前的堆栈中复制答案(所有这些),我的php版本是7.3.11,当我启动这个php时,他只是变为空白,没有任何错误如何在php会话中发出post请求?,php,session,Php,Session,无法在会话中发出post请求,有人能帮忙吗?我从以前的堆栈中复制答案(所有这些),我的php版本是7.3.11,当我启动这个php时,他只是变为空白,没有任何错误 <?php define("COOKIE_FILE", "cookie.txt"); session_start(); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); ini_set('error_reporting', E_ALL);
<?php
define("COOKIE_FILE", "cookie.txt");
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('error_reporting', E_ALL);
function httpPost($url, $data)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0');
curl_setopt($curl, CURLOPT_COOKIEJAR, COOKIE_FILE);
curl_setopt($curl, CURLOPT_COOKIEFILE, COOKIE_FILE);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
httpPost('myurl', array('ss'=>'ss'));
可能在您的请求中有一些重定向(深度),因此在这种情况下使用
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 10);
其中10是最大深度,请遵循以下步骤 是否检查apache错误日志?还要添加curl错误代码和调试,如:@BhAvikGajjar当然,没有错误或警告@BhAvikGajjar在curlcheck错误日志中是否没有错误?