How can I make flashget "normal and valid" download the custom file link in the session? JSP/Servlet implementation!

Source: Internet
Author: User

<%
// ================================================ ========================================================== ==============================
/*
As a supplement to the previous two articles:
Http://blog.csdn.net/playyuer/archive/2004/08/02/58281.aspx
Http://blog.csdn.net/playyuer/archive/2004/08/02/58430.aspx

How can I make flashget "normal and valid" download the custom file link in the session? JSP/Servlet implementation!
IE must have no problems!
As long as your page is in the session (for example, in the logged-in status), you can download it normally!
Flash get cannot be tested!
Flashget cannot get any value in the session!
But we can adopt a flexible approach!
Log on to flashget during download!
That is, let flashget send a request with the Authorization header!
You can use:
Select "log on to the server" and enter the user name and password to download and log on to the server!
This is also reasonable. You do not need to download ie. Of course, you need another method to determine whether the download is legal!
Of course, you can also use the URL in the following format to download in IE and flashget:
Http: // playyuer: microshaoft @ localhost: 8180/examples/basic/servlet/download. jsp
Server Program The Authorization header information can be read from the request, and the request determines whether the download is permitted!
Careful friends should also note that
Http://blog.csdn.net/playyuer/archive/2004/08/02/58281.aspx
I also replied:
Anti-leech Processing
Http://blog.csdn.net/playyuer/archive/2004/08/02/58281.aspx#58285
Http://blog.csdn.net/playyuer/archive/2004/08/02/58281.aspx#58287
*/
/*
The file name can be saved as: Download. jsp
For HTTP requests and responses, you can use flashget to download http: // connection process monitoring:
The blue part is: client request
Purple: Server Response
:
Http://blog.csdn.net/images/blog_csdn_net/playyuer/30110/o_FlashGet.gif
For more information, see the following flashget session List:

*/

Boolean OK = false;

// Java. Io. printwriter out = response. getwriter (); // Servlet
// It is not in the session or downloaded using flashget.
If (request. getheader ("Authorization ")! = NULL)
{
// Obtain the user name and password from the request
// The request format is:
// Authorization: Basic cgxhexl1zxi6twljcm9zagfvznq =
// The username and password are base64-encoded by the client.
// Therefore, decode:
String S = new string (new sun. Misc. base64decoder (). decodebuffer (request. getheader ("Authorization"). substring (6). Trim ()));
Int I = S. indexof (":");
String user = S. substring (0, I); // User Name
String Password = S. substring (I + 1); // Password
// You can write your own verification rules here.
// In this example, the verification rules are:
// Username: playyuer
// Password: microshaoft
If (user. Equals ("playyuer") & password. Equals ("microshaoft "))
// If the verification succeeds, you can use flashget to download the file and set the flag.
OK = true;
}
If (! OK)
{
If (request. getsession (). getattribute ("isloginedd ")! = NULL)
{
// Allow direct download with IE and set the flag
OK = true;
}
}

// ================================================ ========================================================== ==============================

If (OK = true)
{
// You can use the file on your server and its path
String S = "I: // setupres // sun // j2re-1_4_2_05-windows-i586-p.exe ";
// String S = "E: // tree. mdb ";

// Randomaccessfile can also be implemented after testing. If you are interested, remove the annotation and comment out the fileinputstream statement.
// Java. Io. randomaccessfile RAF = new java. Io. randomaccessfile (S, "R ");

Java. Io. File F = new java. Io. file (s );
Java. Io. fileinputstream FCM = new java. Io. fileinputstream (f );

Response. Reset ();

Response. setheader ("server", "playyuer@Microshaoft.com ");

// Tell the client to allow multi‑thread download of resumable Data Transfer
// The response format is:
// Accept-ranges: bytes
Response. setheader ("Accept-ranges", "bytes ");

Long p = 0;
Long L = 0;
// L = Raf. Length ();
L = f. Length ();

// If resumable data transfer is not enabled for the first time, the status is 200 by default, and no explicit settings are required.
// The response format is:
// HTTP/1.1 200 OK

If (request. getheader ("range ")! = NULL) // start byte of the file block requested by the client
{
// If the range of the downloaded file is not all, declare to the client to support and start file block download
// Set the status
// The response format is:
// HTTP/1.1 206 partial content
Response. setstatus (javax. servlet. http. httpservletresponse. SC _partial_content); // 206

// Get the starting byte from the request
// The request format is:
// Range: bytes = [start byte of the file block]-
P = long. parselong (request. getheader ("range"). replaceall ("bytes =", ""). replaceall ("-",""));
}

// The length of the downloaded file (or block)
// The response format is:
// Content-Length: [total file size]-[start byte of the downloaded file block requested by the client]
Response. setheader ("Content-Length", new long (L-P). tostring ());

If (P! = 0)
{
// Not the first download,
// The response format is:
// Content-range: bytes [start byte of the file block]-[total file size-1]/[total file size]
Response. setheader ("content-range", "bytes" + new long (P ). tostring () + "-" + new long (L-1 ). tostring () + "/" + new long (l ). tostring ());
}

// Response. setheader ("connection", "close"); // if this sentence exists, ie cannot be used for direct download.

// Make the client download directly
// The response format is:
// Content-Type: Application/octet-stream
Response. setcontenttype ("application/octet-stream ");

// Specify the default download file name for the client download
// The response format is:
// Content-Disposition: attachment; filename = "[file name]"
// Response. setheader ("content-disposition", "attachment; filename =/" "+ S. substring (S. lastindexof ("//") + 1) + "/"); // The randomaccessfile can also be tested. If you are interested, remove the annotation and comment out the fileinputstream statement.
Response. setheader ("content-disposition", "attachment; filename =/" "+ F. getname () + "/"");

// Raf. Seek (P );
FS. Skip (P );

Byte [] B = new byte [1024];
Int I;
// While (I = Raf. Read (B ))! =-1) // tested randomaccessfile can also be implemented. If you are interested, remove the annotation and comment out the fileinputstream statement.
While (I = Fi. Read (B ))! =-1)
{
Response. getoutputstream (). Write (B, 0, I );
}
// Raf. Close (); // The randomaccessfile can also be tested. If you are interested, remove the annotation and comment out the fileinputstream statement.
FCM. Close ();
}
Else
// Set the verification failure status to reject the download request
// The response format is:
// HTTP/1.1 401 unauthorized
Response. setstatus (javax. servlet. http. httpservletresponse. SC _unauthorized );
%>

// Configure //-----------------------------------------------------------------------------------

In flashget
A set of first direct downloads without resumable http session processes:
client requests:
Mon Aug 02 05:46:36 2004 connection download2.flashfxp.com: 80
Mon Aug 02 05:46:36 2004 connection download2.flashfxp.com [IP = 66.98.228.125: 80]
Mon Aug 02 05:46:37 2004 connected.
Mon Aug 02 05:46:37 2004 get/zip/flashfxp_30_setup.exe HTTP/1.1
Mon Aug 02 05:46:37 2004 HOST: download2.flashfxp.com
Mon Aug 02 05:46:37 2004 accept: */*
Mon Aug 02 05:46:37 2004 Referer: http://playyuer.microshaoft.com
Mon Aug 02 05:46:37 2004 User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
Mon Aug 02 05:46:37 2004 Pragma: No-Cache
Mon Aug 02 05:46:37 2004 cache-control: No-Cache
Mon Aug 02 05:46:37 2004 authorization: basic mgrhetpjy2zfzg93bmxvywq =
Mon Aug 02 05:46:37 2004 connection: Close

Server Response:
Mon Aug 02 05:46:37 2004 HTTP/1.1 200 OK
Mon Aug 02 05:46:37 2004 date: Sun, 01 Aug 2004 21:46:29 GMT
Mon Aug 02 05:46:37 2004 server: Apache/1.3.27 (UNIX )? (Red-hat/Linux) mod_fastcgi/2.2.12 mod_gzip/1.3.19.1a mod_jk/1.2.0 mod_perl/1.26 PHP/4.3.3 FrontPage/5.0.2 mod_ssl/2.8.12 OpenSSL/0.9.6b
Mon Aug 02 05:46:37 2004 last-modified: Fri, 30 Jul 2004 18:41:18 GMT
Mon Aug 02 05:46:37 2004 etag: "4f80fa-1ecf20-450a964e"
Mon Aug 02 05:46:37 2004 accept-ranges: bytes
Mon Aug 02 05:46:37 2004 Content-Length: 2019104
Mon Aug 02 05:46:37 2004 connection: Close
Mon Aug 02 05:46:37 2004 Content-Type: Application/octet-stream

?

HTTP session process for resumable data transfer:
client request:
Mon Aug 02 05:27:05 2004 is connecting download2.flashfxp.com: 80
Mon Aug 02 05:27:05 2004 is connecting download2.flashfxp.com [IP = 66.98.228.125: 80]
Mon Aug 02 05:27:05 2004 connected.
Mon Aug 02 05:27:05 2004 get/zip/flashfxp_30_setup.exe HTTP/1.1
Mon Aug 02 05:27:05 2004 HOST: download2.flashfxp.com
Mon Aug 02 05:27:05 2004 accept: */*
Mon Aug 02 05:27:05 2004 Referer: http://playyuer.microshaoft.com
Mon Aug 02 05:27:05 2004 User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
Mon Aug 02 05:27:05 2004 range: bytes = 191621-
Mon Aug 02 05:27:05 2004 Pragma: No-Cache
Mon Aug 02 05:27:05 2004 cache-control: no-Cache
Mon Aug 02 05:27:05 2004 authorization: Basic mgrhetpjy2zfzg93bmxvywq =
Mon Aug 02 05:27:05 2004 connection: Close

Server Response:
Mon Aug 02 05:27:06 2004 HTTP/1.1 206 partial content
Mon Aug 02 05:27:06 2004 date: Sun, 01 Aug 2004 21:26:57 GMT
Mon Aug 02 05:27:06 2004 server: Apache/1.3.27 (UNIX )? (Red-hat/Linux) mod_fastcgi/2.2.12 mod_gzip/1.3.19.1a mod_jk/1.2.0 mod_perl/1.26 PHP/4.3.3 FrontPage/5.0.2 mod_ssl/2.8.12 OpenSSL/0.9.6b
Mon Aug 02 05:27:06 2004 last-modified: Fri, 30 Jul 2004 18:41:18 GMT
Mon Aug 02 05:27:06 2004

 

client request:
Fri Aug 06 08:25:28 2004 connecting localhost: 8180
Fri Aug 06 08:25:28 2004 connecting localhost [IP = 127.0.0.1: 8180]
Fri Aug 06 08:25:28 2004 connected.
Fri Aug 06 08:25:28 2004 get/examples/basic/servlet/download1.jsp HTTP/1.1
Fri Aug 06 08:25:28 2004 HOST: localhost: 8180
Fri Aug 06 08:25:28 2004 accept: */*
Fri Aug 06 08:25:28 2004 Referer: http: // server
Fri Aug 06 08:25:28 2004 COOKIE :. aspxauth = compatible
Fri Aug 06 08:25:28 2004 User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
Fri Aug 06 08:25:28 2004 range: bytes = 1607796-
Fri Aug 06 08:25:28 2004 Pragma: No-Cache
Fri Aug 06 08:25:28 2004 cache-control: no-Cache
Fri Aug 06 08:25:28 2004 authorization: Basic cgxhexl1zxixok1py3jvc2hhb2z0
Fri Aug 06 08:25:28 2004 connection: Close

Server Response:
Fri Aug 06 08:25:28 2004 HTTP/1.1 401 unauthorized
Fri Aug 06 08:25:28 2004 Server: resin/2.1.14
Fri Aug 06 08:25:28 2004 cache-control: Private
Fri Aug 06 08:25:28 2004 set-COOKIE: JSESSIONID = aGzRDyz-b3ye; path =/
Fri Aug 06 08:25:28 2004 Content-Type: text/html
Fri Aug 06 08:25:28 2004 transfer-encoding: chunked
Fri Aug 06 08:25:28 2004 date: Fri, 06 Aug 2004 00:25:27 GMT
Fri Aug 06 08:25:28 2004 error occurred!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.