Php 使用CURL和cookies登录并从extranet页面收集数据

Php 使用CURL和cookies登录并从extranet页面收集数据,php,curl,sap,Php,Curl,Sap,我正在写一个脚本,它将使用cookie登录到SEP外联网页面,并使用CURL获取一些cookie(我需要在此页面上收集有关产品价格的数据)。我的代码如下所示: //username and password of accounts //trim-remove whitespaces from strings $username = trim("John"); $password = trim("123"); //set the directory for the cookie using d

我正在写一个脚本,它将使用cookie登录到SEP外联网页面,并使用CURL获取一些cookie(我需要在此页面上收集有关产品价格的数据)。我的代码如下所示:

//username and password of accounts
//trim-remove whitespaces from strings

$username = trim("John");
$password = trim("123");

//set the directory for the cookie using defined document root var
$dir = DOC_ROOT."/ctemp";
//build a unique path with every request to store
//the info per user with custom func.
$path = build_unique_path($dir);

//login form action url
$url="http://destination.com";
$postinfo = "email=".$username."&password=".$password;

$cookie_file_path = $path."/cookie.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
//set the cookie the site has for certain features, this is optional
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT,
    "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
curl_exec($ch);
我得到一个错误:

“网络错误:找不到404- " . 它与 服务器无法正常/完全收集cookie,我收到: 活动、sap usercontext、sap appcontext、sap hostid和MYSAMSSO2, 这不是我需要的

有人知道为什么这个代码不起作用吗


我试图更改curl_setopt参数,但没有成功。我还查找了类似的问题或示例,但我没有发现任何有用的内容。当我查看页面时,它并不存在。可能是你试图访问的页面不存在吗?我更改了url,这只是一个例子当我查看页面时,它不存在。可能是你试图访问的页面不存在吗?我更改了url,这只是一个例子