2010-01-01 111 views
0

我想從遠程服務器複製文件,但似乎遠程主機正在使用會話,並且需要cookie。cURL without cURL-問題

好,我用這個方法 定義變量後...

$url="http://example.com/stamp/stamp.jsp?tp=&arnumber=5255176&isnumber=5255174"; 
$nn = "\r\n"; 
$cookies=""; 
$request = GET . " " . str_replace (" ", "%20", $url) . " HTTP/1.1" . $nn . "Host: " . $host . $nn . "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14" . $nn . "Accept: */*" . $nn . "Accept-Language: en-us;q=0.7,en;q=0.3" . $nn . "Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7" . $nn . "Pragma: no-cache" . $nn . "Cache-Control: no-chache" . $nn . $proxyauthorization . $referer . $cookies . "Connection: Close"; 

$fp= socksopen($Proxy,$port, $errno, $errstr, 15); 

socket_set_timeout ($fp, 120); 

fputs ($fp, $request); 

fflush ($fp); 

//read header 

$i = 1; 

do { 

$header.= @fgets ($fp, 128); 

$i++; 

} while (strpos ($header, $nn . $nn) === false); 

echo $header; 

fclose ($fp); 

現在我有餅乾的URL說頭:

HTTP/1.1 302 Moved Temporarily Content-length: 0 Content-type: text/html Server: Sun-ONE-Web-Server/6.1 Date: Mon, 28 Dec 2009 13:40:53 GMT Set-cookie: ERIGHTS=5YAaxxmNsMuTK87E1TCAohwDRuyqBaCgM-oehmg24bkzHplCtmgn7zMA==;path=/;domain=.example.org Set-cookie: WLSESSION=1528980108.20480.0000; expires=Tue, 29-Dec-2009 13:40:52 GMT; path=/ Location: http://example.com/stamp/stamp.jsp?tp=&arnumber=5255176&isnumber=5255174"&tag=1 Via: 1.1 proxy-server1 Proxy-agent: Sun-Java-System-Web-Proxy-Server/4. 

然後我做了一些刺痛代碼和建這在代碼中:

$cookies="cookie: ERIGHTS=5YAaxxmNsMuTK87E1TCAohwDRuyqBaCgM-oehmg24bkzHplCtmgn7zMA==,WLSESSION=1528980108.20480.0000"; 

重新請求具有相同方法的url上述 OD提到,再次我有與其他餅乾

它接縫遠程網站每次把我作爲一個首次訪問者,並設置新的cookie獲得

有一件事是相同的標題,我試圖複製該文件是一個.pdf文件究竟

我檢查了我的瀏覽器,結果:

說的網址是:

http://example.com/stamp/stamp.jsp?tp=&arnumber=5344171&isnumber=5344169

我檢查URL的源代碼,它包含一個重定向到另一個頁面,要麼是iframe中的JavaScript頁面

源(從我的瀏覽器)

 <frameset rows="65,35%"> 
<frame src="http://example.com/stamp/banner.jsp" frameborder="0" framespacing="0" framepadding="0" scrolling="no" /> 
<frame src="http://example.com/stampPDF/getPDF.jsp?tp=&arnumber=5255176&isnumber=5255174" frameborder="0" /> 

正如你看到的,當我點擊的URL,它重定向我URL2 的URL2是這樣的:http://example.com/stampPDF/getPDF.jsp?tp=&arnumber=5255176&isnumber=5255174

URL2包含.pdf文件我可以很容易地複製(下載)。

但是當我使用我上面提到的代碼時,$url="http://example.com/stamp/stamp.jsp?tp=&arnumber=5255176&isnumber=5255174" 它需要cookie來設置我的請求,當接收到cookie並設置併發送cookies與我的請求時它再次回覆一個新的cookie!

傢伙們怎麼了?

+0

你爲什麼要重新實現一個HTTP庫?捲曲有問題嗎?它有命令行選項來傳遞Cookie,重定向後,等... – gahooa 2010-01-01 05:24:09

+0

cURL將無法與代理正常工作,我試過5代理,但只有其中一個用cURL解決我不知道爲什麼,所以我建我自己的代碼。 – Alireza 2010-01-01 05:30:26

回答