所以我正在努力解决下面的代码。我有一个java服务文件和PHP试图抓取文件并保存。我可以在浏览器中从servlet下载文件。我可以使用php代码下载任何文件或网页(无论是否为SSL)。但是对于我的生活我不能从这个servlet下载php!我对PHP非常熟悉,但对java并不是很熟悉,如果有帮助,我没有编写那个servlet。但是,我可以编辑代码的任何一端。谢谢!!
JAVA:
@Override
public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
try {
String fileName = "/tmp/DongleUpdate.jar";
File f = new File( "/tmp/DongleUpdate.jar" );
response.setContentType( "application/zip" );
response.setHeader( "Content-Disposition", "attachment;filename=\"" +
fileName + "\"" );
byte[] arBytes = new byte[( int ) f.length()];
FileInputStream is = new FileInputStream( f );
is.read( arBytes );
ServletOutputStream op = response.getOutputStream();
op.write( arBytes );
op.flush();
} catch( IOException ioe ) {
ioe.printStackTrace();
}
}
PHP:
$ch = curl_init($file);
curl_setopt($ch, CONNECTTIMEOUT, 10);
curl_setopt($ch, TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
curl_setopt($curl, CURLOPT_GET, true);
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
curl_setopt($cURL,CURLOPT_HTTPHEADER,array(
"Accept: application/zip"
));
$rawdata=curl_exec($ch);
curl_close ($ch);
$fp = fopen($saveloc,'w');
fwrite($fp, $rawdata);
fclose($fp);
我已经尝试了我能想到的每个版本的curl选项。我是堆栈溢出的新手,但如果有帮助我可以给某人发消息。此外,如果它有助于这里是来自fiddler的链接的原始连接输出:
CONNECT XXXX:8443 HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0
Connection: keep-alive
Connection: keep-alive
Host: XXXX
A SSLv3-compatible ClientHello handshake was found. Fiddler extracted the parameters below.
Version: 3.1 (TLS/1.0)
Random: XXXX
SessionID: empty
Extensions:
elliptic_curves XXXX
ec_point_formats 01 00
SessionTicket TLS empty
NextProtocolNegotiation empty
Ciphers:
[00FF] TLS_EMPTY_RENEGOTIATION_INFO_SCSV
[C00A] TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
[C014] TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA
[0088] TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
[0087] TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA
[0039] TLS_DHE_RSA_WITH_AES_256_SHA
[0038] TLS_DHE_DSS_WITH_AES_256_SHA
[C00F] TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
[C005] TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
[0084] TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
[0035] TLS_RSA_AES_256_SHA
[C007] TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
[C009] TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
[C011] TLS_ECDHE_RSA_WITH_RC4_128_SHA
[C013] TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA
[0045] TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
[0044] TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA
[0033] TLS_DHE_RSA_WITH_AES_128_SHA
[0032] TLS_DHE_DSS_WITH_AES_128_SHA
[C00C] TLS_ECDH_RSA_WITH_RC4_128_SHA
[C00E] TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
[C002] TLS_ECDH_ECDSA_WITH_RC4_128_SHA
[C004] TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
[0096] TLS_RSA_WITH_SEED_CBC_SHA
[0041] TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
[0005] SSL_RSA_WITH_RC4_128_SHA
[0004] SSL_RSA_WITH_RC4_128_MD5
[002F] TLS_RSA_AES_128_SHA
[C008] TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
[C012] TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
[0016] SSL_DHE_RSA_WITH_3DES_EDE_SHA
[0013] SSL_DHE_DSS_WITH_3DES_EDE_SHA
[C00D] TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
[C003] TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
[FEFF] SSL_RSA_FIPS_WITH_3DES_EDE_SHA
[000A] SSL_RSA_WITH_3DES_EDE_SHA
压缩: [00] NO_COMPRESSION
答案 0 :(得分:0)
老帖但是如果有人关心我只是一个白痴并做了剪切和粘贴错误所以我的卷曲选项有两个不同的变量标记:/
答案 1 :(得分:-1)
如果Java端设置Content-length
标题,也许你会好运。
浏览器通常可以不使用它,但这里......?