How to make the FlashGet "Normal Legal" to download the custom file link in the session? JSPservlet implementation!

zhaozj2021-02-16  140

<% / / =============================================== ============================================================================================================================================================================================================= = / * As a supplement of the upper 2: http://blog.9cbs.net/playyuer/archive/2004/08/02/58281.aspx http://blog.9cbs.net/playueer/archive/2004/08 / 02/58430.aspx

How to make FlashGet "Normal Legal" download SESSION custom file link? JSP / servlet implementation! IE is definitely no problem! As long as your page is in session (for example, in the place where you have logged in), you You can download it normally! FlashGet is not available! Flashget does not get any value in the session! But we can take a variety of ways! Let FlashGet will be logged in when downloading! Let's get the flashget to send a request with the Authorization header! At the FLASHGET download, pass the login to the server and fill in the username and password to implement the download! This is reasonable, do not use IE download, of course, additional means to determine if the download is legal! Of course, you can use the following format URL in IE and flashget Normal download: http: // playyuer: microshaoft @ localhost: 8180 / examples / basic / serval program can read the information of the Authorization header from the request, and determine if it is legal, decide whether to allow download ! Careful friends should also notice http://blog.9cbs.net/playyueer/archive/2004/08/02/58281.aspx I also replied: The anti-theft chain handles http://blog.9cbs.net/ Playyuer / Archive / 2004/08/02 / 58281.aspx # 58285 http://blog.9cbs.net/playyueer/archive/2004/08/02/58281.aspx#58287//> File name can be available: Download.JSP HTTP protocol request and response session procedure can be downloaded by using FlashGet to download the HTTP: // connection: The blue section is: the client requests the purple portion: the server side response is as shown in the figure: http: // blog. 9cbs.net/Images/blog_9cbs_net/playyuer/30110/O_FLASHGET.GIF or see, back FlashGet session list: * /

Boolean OK = FALSE;

//java.io.printwriter out = response.getwriter (); // servlet // is not in Session, or downloading if it is downloaded with flashget (Request.getHeader ("Authorization")! = null) {// Request Get the format of the username and password // request: // Authorization: Basic cgxhexl1zxi6twljcm9zagfvznq = //, where the username and password are encoded by the client Base64, so to decode: string s = new string (new sun.misc.base64decoder ). depast.getHeader ("authorization"). Substring (6) .trim ())); int i = s.indexof (":"); string user = s.substring (0, i); // User name string password = s.substring (i 1); // password // Here you can rewrite your own verification rule // This example verification rule is: // Username: Playyuer // Password: Microshaoft IF (User . Equals ("Playyuer" && password.equals ("microshaoft")) // If the verification is passed, allow the FlashGet to download, and set the flag OK = true;} if (! ok) {if (Request.getSession (). GetAttribute ("islogineddd")! = null) {// Allow IE to download directly, and set the flag OK = true;}} // ==================== ============================================================================================================================================================================================================= ===========================

If (ok == true) {// You can use the files 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";

// Test RandomaccessFile can also be achieved, interested in removing the comment and comment out the FileInputStream version of the statement //java.io.randomaccessFile Raf = new java.io.randomaccessFile (S, "R");

Java.io.file f = new java.io.file (s); java.io.fileinputstream FII = new java.io.fileinputStream (f); response.reset ();

Response.setHeader ("Server", "Playyuer@microshaoft.com");

// Tell the client to allow breakpoints to renew multi-thread connection download // response format is: // accept-ranges: bytes response.setheader ("accept-ranges", "bytes");

Long P = 0; long L = 0; // l = raf.length (); l = f.Length ();

// If it is the first time, there is no breakpoint, the status is the default 200, no need to explicitly set // response format: //Http/1.1 200 ok

IF (Request.getHeader ("Range"! = null) // The start byte of the downloaded file block of the client request {// If it is the scope of the download file instead, to declare the file block to the client Download // To set the status // response format is: //http/1.1 206 Partial Content Response.setStatus (javax.servlet.http.httpservletResponse.sc_partial_content); // 206

// The format of the byte // request from the request is: // Range: Bytes = [Start byte of file block] - P = long.parselong (Request.getHeader ("Range"). ReplaceAll (" Bytes = "," "). ReplaceAll (" - "," "));

// Download the file (or block) length // The format of the response is: // Content-length: [Total size of the file] - [Start byte of the file block of the client request] Response.setHeader ("Content) -Length, New long (l - p) .tostring ());

IF (p! = 0) {// is not from the start of downloading, // responding is: // content-range: BYTES [Fault byte] - [Total size of files - 1] / [file Total size] Response.setHeader ("Content-Range", "Bytes" new long (p) .tostring () "-" new long (l -1) .tostring () "/" new long (l) .toString ());

//Response.setheader ("Connection "," close "); // If there is this sentence, you can't download it directly.

/ / The format of the client directly downloads // responds directly is: // content-type: Application / OCTET-stream response.setContentType ("Application / Oct-stream");

/ / To download the specified default download file name // response to the client: // content-disposition: attachment; filename = "[file name]" //Response.setheader ("in", ",", "attachment; Filename = / "" s.substring (S.LastIndexof ("//") 1) "/"); // Test RandomaccessFile can also be implemented, interested can remove the comment and comment out the FileInputStream version Statement Response.setHeader ("Content-Disposition", "Attachment; FileName = /" " F.GetName () " /"" ";//raf.seek (P); fis.skip (p);

Byte [] b = new byte [1024]; INT i; // while ((i = raf.read (b)))! = -1) // Test RandomaccessFile can also be implemented, interested can remove the comment, and Note the FileInputStream version of the statement while ((i = fis.read (b))! = -1) {response.getOutputStream (). Write (b, 0, i);} //raf.close();// Test RandomaccessFile can also be implemented, interested in removing the comment and comment out the fileInputstream version of statement fis.close ();} else // To set the verification failure, refuse to download the request // Response format is: // http / 1.1 401 unauthorized response.setstatus (javax.servlet.http.httpservletResponse.sc_unauthorized);%>

/ / -------------------------------------------------------------------------------------------- -----------------------------------

In a set of direct downloads in FlashGet, there is no breakpoint to return HTTP session: client request: MON aug 02 05:46:36 2004 is connected Download2.Flashfxp.com:80Mon aug 02 05:46:36 2004 is connected 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.1mon aug 02 05:46:37 2004 Host: Download2.flashfxp.common aug 02 05:46:37 2004 Accept: * / * mon aug 02 05:46:37 2004 Referer: http://playyuer.microshaoft.common 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-cachemon aug 02 05:46:37 2004 Cache-Control: no-cachemon Aug 02 05:46:37 2004 Authorization: Basic mgrhetpjy2zfzg93bmxvywq = mon Aug 02 05:46:37 2004 Connection: Close server side response: MON aug 02 05:46:37 2004 http / 1.1 200 okmon aug 02 05:46:37 2004 Date: Sun, 01 AUG 2004 21:46:29 Gmtmon 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.1 A 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.6bmon aug 02 05:46:37 2004 Last-modified: fri, 30 jul 2004 18:41:18 gmtmon aug 02 05:46:37 2004 ETAG: "4F80fa-1ec20-410a964e" MON AUG 02 05:46: 37 2004 ACCEPT-RANGES: BYTESMON AUG 02 05:46:37 2004 Content-Length: 2019104Mon aug 02 05:46:37 2004 Connection: Closemon Aug 02 05:46:37 2004 Content-Type: Application / OcTet-Stream

?

HTTP session process for a set of breakpoints: Mon aug 02 05:27:05 2004 is connected Download2.flashfxp.com: 80Mon aug 02 05:27:05 2004 is connected to download2.flashfxp.com [ip = 66.98.228.125: 80] MON AUG 02 05:27:05 2004 has been connected .mon aug 02 05:27:05 2004 get /zip/flashfxp_30_setup.exe http / 1.1mon aug 02 05:27:05 2004 Host: Download2 . ACCEER: http:05 2004 / 4.0 (compatible; msie 5.00; windows 98) MON AUG 02 05:07:05 2004 Range: Bytes = 191621-mon Aug 02 05:27:05 2004 Pragma: no-cachemon aug 02 05:27:05 2004 cache- Control: no-cachemon aug 02 05:27:05 2004 Authorization: Basic mgrhetpjy2zfzg93bmxvywq = mon Aug 02 05:27:05 2004 CONNECTION: CLOSE server side response: mon Aug 02 05:27:06 2004 http / 1.1 206 Partial ContentMon Aug 02 05:27:06 2004 Date: Sun, 01 Aug 2004 21:26:57 GMTMON 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_pers / 1.26 PHP / 4.3.3 fron TPAGE / 2.8.12 OPENSSL / 0.9.6BMON AUG 02 05:27:06 2004 Last-Modified: Fri, 30 Jul 2004 18:41:18 gmtmon aug 02 05:27:06 2004

Client Request: fri aug 06 08:25:28 2004 is connected Localhost: 8180fri aug 06 08:25:28 2004 is connecting to localhost [ip = 127.0.0.1: 8180] fri aug 06 08:25:28 2004 is connected. Fri Aug 06 08:25:28 2004 get /examples/basic/servlet/download1.jsp http / 1.1fri aug 06 08:25:28 2004 Host: localhost: 8180fri aug 06 08:25:28 2004 accept: * / * Fri Aug 06 08:25:28 2004 Referer: http: // ServerFri Aug 06 08:25:28 2004 Cookie: .ASPXAUTH = BE5BF4ADA48516FFD56ED0B6B5172BF4C33020E9D6348E1A83E8B720E67A56B2026A3C96FC540CE94A7E6D94B368AA608341A04056929872AD3360953D97863448BB7785C75F4136F1CC449B1ECCF5707685CC5D9967D95494321E7585E3CA52CB7961ED7168876DFri 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-cachefri aug 06 08:25:28 2004 Cache-Control: no-cachefri aug 06 08:25:28 2004 Authorization: Basic CGXHEXL1ZXIXOK1PY3JVC2HHB2Z0FRI AUG 06 08:25:28 2004 Connection: Close Server Sign in: fri Aug 06 08:25:28 2004 HTTP / 1.1 401 Unauthorizedfri Aug 06 08:25 : 28 2004 Server: Resin / 2.1.14fri aug 06 08:25:28 2004 Cache-Control: privatefri aug 06 08:25:28 2004 Set-cookie: jsessionid = Agzrdyz-B3YE; PATH = / fri aug 06 08:25 : 28 2004 Content-Type: Text / HTMLFRI AUG 06 08:25:28 2004 Transfer-Encoding: Chunkedfri Aug 06 08:25:28 2004 Date: Fri, 06 Aug 2004 00:25:27 gmtfri aug 06 08:25: 28 2004 has a mistake!

转载请注明原文地址:https://www.9cbs.com/read-8705.html

New Post(0)