简体   繁体   English

没有cURL的cURL问题

[英]cURL without cURL- problem

I wanted to copy files from a remote server, but it seems that the remote host is using session, and needs cookies. 我想从远程服务器复制文件,但似乎远程主机正在使用会话,并且需要cookie。

well I used this method after defining variables... 好,我用定义变量后,这个方法...

$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);

now I have the header with cookies that the url said : 现在我有带有URL的cookie的标头:

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.

then I did some sting code and built this in the code: 然后我做了一些代码,并在代码中构建了它:

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

re-requesting the url with same method mentioned above and again i have got same header with another cookies 用上述相同的方法重新请求URL,我又得到了另一个cookie的相同标题

It seams that the remote website is treating me as a first-time visitor each time and sets new cookies gain 它似乎表明远程网站每次都将我视为首次访问者,并获得了新的Cookie

there is one thing, the file i am trying to copy is a .pdf file exactly 有一件事情,我要复制的文件正是.pdf文件

i checked that by my browser, the results: 我通过浏览器检查了一下结果:

say the URL is: 说URL是:

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

I checked the source code of the URL, it contains a redirection to another page that either is a javascript with iframe 我检查了URL的源代码,它包含重定向到另一个页面或者是带有iframe的javascript

source of the page (from my browser) 该页面的源(从我的浏览器)

     <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" />

as you see when I click the URL, it redirects me to URL2 the URL2 is this: http://example.com/stampPDF/getPDF.jsp?tp=&arnumber=5255176&isnumber=5255174 如您在单击URL时所看到的那样,它将我重定向到URL2,URL2是这样的: http://example.com/stampPDF/getPDF.jsp?tp=&arnumber=5255176&isnumber=5255174 : http://example.com/stampPDF/getPDF.jsp?tp=&arnumber=5255176&isnumber=5255174 tp=&arnumber=5255176&isnumber=5255174

the URL2 contains .pdf file I can easily copy(download). URL2包含.pdf文件,我可以轻松复制(下载)。

but when i use my code mentioned above, $url="http://example.com/stamp/stamp.jsp?tp=&arnumber=5255176&isnumber=5255174" it needs cookies to set with my request, when receive cookies and set and send cookies with my request it again replies a new cookie !! 但是当我使用上述代码时, $url="http://example.com/stamp/stamp.jsp?tp=&arnumber=5255176&isnumber=5255174" ,当我收到Cookie并设置并设置发送带有我的请求的cookie,再次答复新的cookie!

what is wrong guys? 谁错了?

Are you passing over http://example.com/stampPDF/getPDF.jsp?tp=&arnumber=5255176&isnumber=5255174 as the referer? 您是否要通过http://example.com/stampPDF/getPDF.jsp?tp=&arnumber=5255176&isnumber=5255174作为引荐来源? The site may be checking that. 该网站可能正在检查。

May be you should check your cookie-composing logic. 可能您应该检查Cookie组成逻辑。 Name-value pairs in a cookie header are supposed to be separated with ';' Cookie标头中的名称/值对应以';'分隔 not with ',': http://msdn.microsoft.com/en-us/library/aa920098.aspx#wce50concookieheadersanchor2 . 不带'': http://msdn.microsoft.com/en-us/library/aa920098.aspx#wce50concookieheadersanchor2
And (I'm sure you do this) I would double-check all the request headers with Fiddler, HttpAnalyzer or another similar tool. 并且(我确定您会这样做),我将使用Fiddler,HttpAnalyzer或其他类似工具仔细检查所有请求标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM