Get the real address for Software Download! Obtain the URL of response. Redirect redirection.

Source: Internet
Author: User

Http:// Tid = 1550010 & extra = Page % 3d1

In fact, this problem is outdated and has been discussed for n times.
Among them, care4 also said twice. So if you have any problems, you 'd better search for them first. Maybe the problem has been solved.
Http://; Highlight = % 2bcare4
Http://; Highlight = % 2bcare4
Care4CodeA minor disadvantage is that components are required.
The first is. NET Component 2. No, but it is not easy to use components. Is there any way to directly obtain them using ASP?

The answer is yes.
I wrote a simple VB Winsock code.
Http:// t = response. Redirect

At that time, I said that ASP could not be obtained, but I didn't mix it with csdn. Now I have done it.

First, we need to know why the XMLHTTP component cannot get such a jump address.
Use response. Redirect to jump. php contains header ("location", $ URL );
Both methods share the same principle, that is, adding a location field to the output HTTP header.
At the same time, set the returned HTTP status value to 302, And the browser will think that the page of the current request has
Moved to the specified path of location
Why can't XMLHTTP be obtained?
The reason is simple.
The XMLHTTP component is too intelligent to process 302 messages containing the location header. It directly jumps to the final page, that is ~ We cannot see the intermediate process! Bill is smart!

Fortunately, msxml4 provides a new available component: WinHTTP. winhttprequest.5.1, which is also the core of the msxml4 XMLHTTP component. WinHTTP. winhttprequest has a key attribute: option. The sixth index of this attribute indicates whether to automatically jump, then you can easily use the getResponseHeader and getAllResponseHeaders methods of the XMLHTTP component to obtain the returned HTTP header information.

Okay. Now let's look at the code.
Dim ohttp
Set ohttp = server. Createobject ("WinHTTP. winhttprequest.5.1"
Ohttp. Option (6) = 0' disable automatic redirect. The most important thing to do is simply reading data.
Ohttp. settimeouts, 'sets timeout ~ Same as the serverxmlhttp component
Ohttp. Open "get", Surl, false' open the URL in synchronous Mode
If ohttp. Status <> 200 and ohttp. Status <> 302 then
'Http. status' corresponds to the returned HTTP status. If it is 200, it indicates that this is the final page and no location jump.
'If it is 302, it indicates that the URL of the current request has been moved and needs to be redirected according to the HTTP header.
'Basically, we do not want to process the status of other values, but you can also process the status of 440 or other values by yourself!
'Here we will process the returned HTTP header and document content
End if

Okay. The complete code is long.
I passed it to the space and checked it myself.
The code in the default input column is crsky. You can test it and you will know it.
Click to viewSource codeYou can see the source code of this ASP file!

All done. Over. Continue to csdn.

complete code: copy Code the code is as follows:

<% Public function bytes2bstr (v) dim R, I, T, N: r = "" for I = 1 to lenb (v) t = ASCB (midb (V, I, 1) If T <& h80 thenr = R & CHR (t) Elsen = ASCB (midb (v, I + 1, 1) r = R & CHR (clng (t) * & h100 + CINT (n )) I = I + 1end ifnextbytes2bstr = rend function' ========================== ========================================================== ============================== if request. querystring = "viewsource" thendim ofso: Set ofso = server. createobjec T ("scripting. fileSystemObject ") dim ofil: Set ofil = ofso. opentextfile (server. mappath ("URL. ASP ") dim stxt: stxt = ofil. readall () ofil. close: Set ofil = nothing: Set ofso = nothingresponse. contenttype = "text/plain" response. write stxtresponse. endend if %> <? XML version = "1.0" encoding = "gb2312" standalone = "yes"?> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" ""> <HTML xmlns: V = ""> <head> <title> </title> <meta name = "generator" content = "editplus"/> <meta name = "author" content = "eglic"/> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "/> <meta name =" charset "content =" gb2312 "/> <LINK rel =" stylesheet "type =" te XT/CSS "href ="/styles/default.css "/> <style type =" text/CSS "> @ media all {}</style> <script language =" JavaScript" src = "/scripts/default. JS "> </SCRIPT> <script language =" JavaScript "src ="/scripts/XML. JS "> </SCRIPT> <script language =" JavaScript "> // <! -- // --> </SCRIPT> </head> <body> <form action = "" method = "Post"> URL to be detected: <input type = "text" name = "url" size = "50" value = "<% if request. form ("url") <> "" thenresponse. write trim (request. form ("url") elseresponse. write " Downd_id = 8 & downd = 0 & id = 20780 & down = yes "end if %>"/> <input type = "Submit" value = "Submit"/> <input type = "button" value = "view source code" onclick = "javascript: window. open ('<% = urlself %>? Viewsource '); "/> </form> <% public function getabsoluteurl (Surl, byref istep) dim Burl, bdatif istep> 15 thenerr. raise vbobejcterror, "recursive error", "more than 15 layers of recursive nesting may cause Program Crash "End ifif instr (Surl,": // ") <= 0 then Surl =" http: // "& surlif instr (Surl ,"? ")> 0 thendim tmpurl: tmpurl = Split (Surl ,"? ") Burl = tmpurl (0) bdat = tmpurl (1) elseburl = surlbdat =" "End ifresponse. write "<P style =" "border: solid 1px silver; border-top: solid 2px red; padding: 5px; margin: 2px;" ">" response. write "Step" & istep & ":" response. write "preparing to get" & burl & "<br/>" istep = istep + 1if bdat <> "" Then response. write "> parameter:" & bdat & "<br/>" dim ohttp: Set ohttp = server. createobject ("WinHTTP. winhttprequest.5.1 ") ohttp. option (6) = 0' disable automatic Redirect, the most critical 'HTTP. option () ohttp. settimeouts 30000,500, 0ohttp. open "get", Surl, falseon error resume nextohttp. send bdatif err. number <> 0 thenresponse. write "<font color =" "red"> error: "& err. description & "</font> <br/>" Err. cleargetabsoluteurl = "" set ohttp = nothingresponse. write "</P>" Exit functionend ifon error goto 0response. write "> HTTP status:" & ohttp. status & "<br/>" If ohttp. status <> 200 And ohttp. status <> 302 thenresponse. write "<font color =" "red"> HTTP Error: "& ohttp. statustext & "</font> <br/>" Err. cleargetabsoluteurl = "" set ohttp = nothingresponse. write "</P>" Exit functionend ifdim sloca on error resume nextsloca = ohttp. getResponseHeader ("location") if err. number <> 0 thenerr. clearsloca = "" End ifon error goto 0if sloca = "" thenresponse. write "> Content-Type:" & ohttp. getResponseHeader ("C Ontent-type ") &" <br/> "response. write "> Content-Length:" On Error resume nextresponse. write ohttp. getResponseHeader ("Content-Length") if err. number <> 0 then err. clearon error goto 0response. write "<br/>" response. write "> no location header is returned. Continue analysis page <br/>" If ohttp. getResponseHeader ("Content-Type") = "text/html" then' is HTML type before processing dim sbody: sbody = bytes2bstr (ohttp. responsebody) dim R: Set R = new regexpr. mul Tiline = truer. global = truer. ignorecase = truer. pattern = "<meta. + HTTP \-equiv \ = \ "" Refresh \"". + content = \ "" [^ \;] +; Url \ = ([^ \ "" \ s \>] *). * $ "If R. test (sbody) thenresponse. write "> refresh address found <br/>" dim M: Set M = R. execute (sbody) dim trefurl: trefurl = R. replace (M (0 ). value, "$1") if instr (trefurl, ": //") <= 0 then 'no protocol specified, reset dim ind1 according to the location of the current URL: ind1 = rev (Surl, "/") Surl = left (Surl, ind1) trefurl = Surl & trefurlend IFS Et R = nothingset ohttp = nothingresponse. write "> prepare for analysis <u>" & trefurl & "</u> <br/>" response. write "</P>" getabsoluteurl = getabsoluteurl (trefurl, istep) Exit functionelseresponse. write "> no refresh meta redirection found. This may be the final URL <br/>" getabsoluteurl = surlset r = nothingset ohttp = nothingresponse. write "</P>" Exit functionend ifelsegetabsoluteurl = surlset ohttp = nothingresponse. write "</P>" Exit functionend if 'continue to analyze the webpage Content elseresponse. write "> Content-Type:" & ohttp. getResponseHeader ("Content-Type") & "<br/>" response. write "> Content-Length:" On Error resume nextresponse. write ohttp. getResponseHeader ("Content-Length") if err. number <> 0 then err. clearon error goto 0response. write "<br/>" response. write ">>< u> location:" & sloca & "</u> <br/>" response. write "</P>" 'here, a new urlif instr (sloca, ": //") <= 0 then' is generated. Reset dim ind: Ind = direction Rev (Surl, "/") Surl = left (Surl, IND) sloca = Surl & slocaend ifgetabsoluteurl = getabsoluteurl (sloca, istep) end ifend functionif request. form ("url") <> "" thendim istep: istep = 1dim SABS: SABS = getabsoluteurl (TRIM (request. form ("url"), istep) response. write "<strong style =" "color: White; Background-color: red; font-size: 15px; padding: 3px; margin: 10px;" "> the final result is: "& SABS &" </strong> "end if %> <SCRIPT src = "/T/mystat. asp? Siteid = 1 "> </SCRIPT> </body> </html>

Related Article

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.