卷曲的不寻常的会话难度 - 所有简单的解决方案都已经尝试

时间:2017-02-27 20:15:47

标签: php xml curl cookies session-cookies

燮,

我写这里作为我的最后手段,我国的php论坛中没有人可以处理这个问题。如果你能帮助我,我将非常感激。

我无法使用curl从一个网站正确获取会话。所以,基本上我试图提出2个请求。第一个是创建和保存会话,另一个是发出我想要的请求。

所以整个事情是第一个请求没有创建一个正确的会话。它将一些会话保存到文件中,但它不起作用。有趣的是,当我将会话从浏览器复制到文件时,一切正常。

同样,第一个请求将会话保存到文件,但第二个请求返回错误,但是当我将浏览器的cookie值复制到cookie文件(cookie3.txt)时,一切正常。这就像网站知道文件中的会话是由curl制作的。

我尝试了所有东西,提取标题,饼干罐,一切,似乎没有任何工作。以下是获取会话的示例代码之一(使用cookie jar)。

$cookie_file = './cookie3.txt';

if (! file_exists($cookie_file) || ! is_writable($cookie_file)){
    echo 'Cookie file missing or not writable.';
    exit;
}



$chh = curl_init (html_entity_decode($strona));
curl_setopt ($chh, CURLOPT_COOKIEJAR, realpath($cookie_file));
curl_setopt ($chh, CURLOPT_RETURNTRANSFER, true);
curl_setopt($chh, CURLOPT_HEADER, 1);
curl_setopt($chh, CURLOPT_FOLLOWLOCATION, true);
//curl_setopt($chh, CURLOPT_COOKIESESSION, true);
curl_setopt($chh, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)');
$output = curl_exec ($chh);
curl_close($chh);


$ch = curl_init();

curl_setopt($ch, CURLOPT_COOKIEFILE, realpath($cookie_file));
curl_setopt($ch, CURLOPT_URL, $strona);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$posty);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

// in real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS,
//          http_build_query(array('postvar1' => 'value1')));

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


$data = curl_exec($ch);

print_r($data);

这是使用此代码创建的cookie后出现的错误:

<partial-response><changes><update id="wyszukiwarka_pub_form:messages"><![CDATA[<div id="wyszukiwarka_pub_form:messages" class="ui-messages ui-widget" aria-live="polite" data-global="false" data-summary="data-summary" data-detail="data-detail" data-severity="all,error" data-redisplay="true"></div>]]></update><update id="javax.faces.ViewState"><![CDATA[H4sIAAAAAAAAAM1ZbWwcxRken2Nih4QGJ4FQ4uA4gRBw1r74kthx08SJneTAdgJnzEeEjrnd8d34
9nY3s7O3exfiNqA2fAipElQVCEQkkAAp9A/9Uf4UIUAIEBFEQkggJARUFUIgVKFWbSXad3bv09m9Dwcn3R9zs3fvzLzzPs/7MXNnvkVthsnQlbM4iyWLU1U6hM3UBDbaln7y+htX3fdhKwodQMtUHSsHsMx1FkUdPMWImdJVxTH27EX
i6bfboRX99RztsnNm3kpTG7M0jhtWIj6js8wuk6hE5vtTRE4ndGeCaNaIJebTOGEGIxzLs9RiaNXRcVc
X
FWtJ6XBiFsYM/+7sXc+uNLeoIYQcAxYJWcfQHGqt6rUZ8JTels4xdJOYx5FmsExMSdYzhq4RjUt3RKOaYfFNR5huEMZzt
5KciQpPJyzA0BVlBcY0K1P5o8FRWxarVCnZzBXbp+sqwdr73ezXHz397+9CqOUeV84ijtECqtwcpMphi
9
fSRWyngxemyjK0JKtTBZUfx5gTIu0crVB1GavTQi5GuCm+XY7AIhytt3MaTVMPBAVzPIUTKtk1G6cKDw/uKBuw1Gspmxe2uRX0lUxLK2gvWhVWkIgqTeHkBOEpXRlzAEHTpLpWUKxluWvJa7x9g+h8Odz5w6Z9Xx7
jIVduVUmuLPHcbx6J/f2ec79wQQc9enSWlLCB5RTxmzCaMdTov/Cnavj+DcsLprvW3oakjccr+XjESqhUzmt4H+AlZeCrUV22MoDGjYoubzmB0HwOxjijWnL45XPTf/u66/jBIgdbOOqqRJVkBaIjMgddxkTfMBz7OMr1ZSmxzb4KHWjlC95qFDWSnBTPqN17Izu29YbDO7uxO9c4NT
nRCNvd09xGehyXBOvtv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IUlvCbL1ARhXrxS8DIoyHp13TBd3DUnCOr84/fw/T54aDIkysHBMZ5WxadLKJAj77Znfd13+xOePFknUXsJy56XH0lNkx6VXZKlXiQxcZE042t6IA/OcSswUIWUnrlK+t1GP4IyQGlTtF0WzwWiGzGcrNigwdgqG12Nsh3dBBkU2BLbuo+Pzpszoiij1YaJJ6A
3/teulb54y//SPIjlRGYptl4AUb1bbtU1oEq4bNoTptgZ5uchxt+t63UNf0dPF62n4aUMFK/svvX9c708xAyhmUDO3OLE24ChfWrQWnUXnHff1vQKvuv1nw0xOwXeqRprQ3tV5sM6xZkdESF1QbTqJdt
UvCi07n1SJolE8O1LaTGCdOofuX8AxYqgfTqlDjReqQTotRtG6rjqEjuY0nKGyd4dplhZC7kLI4ejmgN
O
Hqts4nlYtOa/bi1Q9bGlo6eZ4XetGatCvXrvA8sfnErOZRRrIM6Mwb91LMqbbUUiG3lXi6f/CU6vYamTKJTClWQrAq8V/Ei3rIAvMUGZy8XJdgxeMh5UFhJKaF4vhC44kMbSngbsl2EPc9jYRp5V/aQWGkwfRyQVcevVDONnZzKVXLcUWI6YE3CDNMJy/uLcTv0Q31TePq1YgRBmUbh6iwXBvONIEQkUVFgOMSKN/xU7ljNLV1U8a+Jz/AU77FZdiHgAA]]></update></changes></partial-response>

以下是使用算法后的示例cookie3.txt文件:

# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_site.com    FALSE    /    FALSE    0    JSESSIONID    3b-cKghsA2BoutqFYZzc0Min

0 个答案:

没有答案