Curl不会像通常使用cookiejar那样将cookie保存在cookie jar文件中,
我在Windows上,并且使用的是绝对路径,因此iis能够生成文件,因此它没有文件权限或文件夹权限
为弄清我启用并在文件中打印详细的curl的原因,我注意到以下引起我注意的消息
* cookie 'cookienamehere' dropped, domain 'domainname' must not set cookies for 'domainname'
我在Google上搜索了很多内容,在这里也收到了类似的消息,但没有运气,没人在任何地方提及此事
运行下面的代码时,成功生成了cookie文件,但仅包含以下内容
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
内部没有保存一个Cookie, 但是如果您看一下curl的全部详细信息,您会注意到我实际上是从服务器接收cookie,但是Curl不会将cookie保存在文件中,这使我无法使用cookie来确保我专门用于服务器。
从这里获取完整的详细信息
* upload completely sent off: 116 out of 116 bytes
< HTTP/1.1 200 OK
< Cache-Control: no-cache
< Pragma: no-cache
< Content-Type: application/json; charset=utf-8
< Expires: -1
< Server: Microsoft-IIS/10.0
< X-AspNet-Version: 4.0.30319
* cookie 'ASP.NET_SessionId' dropped, domain 'bluepc' must not set cookies for 'bluepc'
< Set-Cookie: ASP.NET_SessionId=mdwxuw2comshi4x55ukbpinx; path=/; HttpOnly
* cookie '.eti_ASPXAUTH' dropped, domain 'bluepc' must not set cookies for 'bluepc'
< Set-Cookie: .eti_ASPXAUTH=3C58F15EE0B8CCFAB5D1C8C6C1D24EFB3A6EBDA01C783E48713639B95621467C625E0AFA85D4F851CECDF842B6C306849E3A183091582A1AD6972F47DC6C1A03A4C638D98ECB32CBB3A7FBB1E4D8C2E8CC5862F23DC5E9771EED39F88C8B8FE29B85227F47C3568ED0EF54408EC56F334A23A581A00DE646796CE2A8E8BFCBC106936AC7EAC779B0D433AAB5A2DF8C92; path=/; HttpOnly
* cookie 'eti_sessionInfo' dropped, domain 'bluepc' must not set cookies for 'bluepc'
< Set-Cookie: eti_sessionInfo=YgBsAHUAZQBwAGMAXABzAHEAbAAyADAAMQA3AKcAUwBpAHMAdABlAG0AYQBfAGUAbQBwAHIAZQBzAGEAcwCnAGgAZQBsAGQAZQCnAEUAeAAgADIAMAAxADkApwAxAKcAUABUAC0AUABUAA==; path=/
< X-Powered-By: ASP.NET
< Date: Thu, 13 Jun 2019 15:01:51 GMT
< Content-Length: 131327
<
* Connection #0 to host bluepc left intact
下面是我用来连接,生成文件并将详细文件转储到文件并从服务器转储变量的php代码
<?php
$url = 'http://bluepc/ERPV18/api/Shell/LoginUser/';
//Initiate cURL.
$ch = curl_init($url);
//The JSON data.
$jsonData = array(
'login' => 'user',
'password' => 'pass',
'idioma' => 'pt-pt',
'server' => 'bluepc\\sql2017',
'sistema' => 'Sistema_empresas'
);
//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);
$fp = fopen('c:/cookies/errorlog.txt', 'w');
curl_setopt($ch, CURLOPT_COOKIEFILE, "C:\cookies\cookieFileTeste.txt");
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
curl_setopt( CURLOPT_COOKIE, "name=daniel; present=yes;");
//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_STDERR, $fp);
curl_setopt($ch, CURLOPT_COOKIEJAR, "C:/cookies/cookieFileTeste.txt");
//Execute the request
$data=curl_exec($ch);
$version = curl_version();
var_dump($version);
if ($data) {
var_dump($data);
}else
{
echo "Não foi possível abrir o Sistema no Serviço Eticadata";
}
curl_close($ch);
?>
使用所有var_dump在页面上显示html结果
array(9) { ["version_number"]=> int(475136) ["age"]=> int(4) ["features"]=> int(2428829) ["ssl_version_number"]=> int(0) ["version"]=> string(6) "7.64.0" ["host"]=> string(15) "x86_64-pc-win32" ["ssl_version"]=> string(14) "OpenSSL/1.1.1b" ["libz_version"]=> string(6) "1.2.11" ["protocols"]=> array(22) { [0]=> string(4) "dict" [1]=> string(4) "file" [2]=> string(3) "ftp" [3]=> string(4) "ftps" [4]=> string(6) "gopher" [5]=> string(4) "http" [6]=> string(5) "https" [7]=> string(4) "imap" [8]=> string(5) "imaps" [9]=> string(4) "ldap" [10]=> string(5) "ldaps" [11]=> string(4) "pop3" [12]=> string(5) "pop3s" [13]=> string(4) "rtsp" [14]=> string(3) "scp" [15]=> string(4) "sftp" [16]=> string(3) "smb" [17]=> string(4) "smbs" [18]=> string(4) "smtp" [19]=> string(5) "smtps" [20]=> string(6) "telnet" [21]=> string(4) "tftp" } }
string(131327) "{DATA VARDUMP HERE, ITS TO LONG AND USELESS TO WRITE HERE ITS THE SUCCESS RESPONSE FROM THE SERVER, SAYING THAT I CONNECTED WITH SUCCESS ETC ETC...}"
答案 0 :(得分:0)
似乎是CURL错误。
此“功能”值未设置PSL位(1 << 20),这意味着该curl版本遭受7.64.0中存在的cookie解析错误的困扰,已在 7.64.1(commit 299d9660f85),使得curl不接受域名上没有任何点的cookie。 (我正在按名称访问服务器区域设置,这就是为什么它没有任何点的原因)
解决方案:升级(或降级)curl。