2013-12-12 19 views
8

stavo cercando di fare LINK FINDER e fronte 2 problemaasincrono HttpRequest utilizzando WinHttp.WinHttpRequest.5.1 in ASP

Issue 1 (Risolto) :: Impossibile ottenere l'URL della pagina reindirizzata

Questo è stato risolto REFERNCE LINK utilizzando WinHttp.WinHttpRequest.5.1

Issue 2 (Unsolved) :: in grado di utilizzare WinHttp.WinHttpRequ est.5.1 opporsi EVENTI o nessuna richiamata alla richiesta asincrona

richiesta codice sincrono

Set req = CreateObject("WinHttp.WinHttpRequest.5.1") 
req.open "GET", url, FALSE 
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
req.send PostData 

Questo sta lavorando bene ma se devo richiesta multuple, allora la sua assunzione a molto tempo.

ho cercato seguente Asynchronous codice di richiesta ma ottenere errore

Set req = CreateObject("WinHttp.WinHttpRequest.5.1") 
req.open "GET", url, TRUE 
req.OnReadyStateChange = GetRef("req_OnReadyStateChange") 
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
req.send PostData 

Function req_OnReadyStateChange 
    ' do something 
End Function 

Codice 1

Set req = CreateObject("WinHttp.WinHttpRequest.5.1","req_") 
req.open "GET", url, TRUE 
Function req__OnResponseFinished 
    ' do something 
End Function 
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
req.send PostData 

ERRORE - Il computer server remoto non esiste o non è disponibile : 'CreateObject'

Codice 2

Set req = CreateObject("WinHttp.WinHttpRequest.5.1") 
req.open "GET", url, TRUE 
req.OnResponseFinished = GetRef("req_OnResponseFinished") 
Function req_OnResponseFinished 
    ' do something 
End Function 
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
req.send PostData 

ERRORE: L'oggetto non supporta questa proprietà o metodo: 'req.OnResponseFinished

Codice 3

Set req = CreateObject("WinHttp.WinHttpRequest.5.1") 
req.open "GET", url, TRUE 
req.OnReadyStateChange = GetRef("req_OnReadyStateChange") 
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
req.send PostData 
Function req_OnReadyStateChange 
    ' do something 
End Function 

Nella documentazione microsoft, hanno fatto riferimento a WinHttp.WinHttpRequest.5.1 hanno 4 eventi.

  1. OnError
  2. OnResponseDataAvailable
  3. OnResponseFinished
  4. OnResponseStart

ma non ho ottenuto esempio di come utilizzare questo evento, non sono in grado di utilizzare questi eventi in ASP.

Speranza per una risposta rapida ...

risposta

2

hai provato a utilizzare una Sub invece di una funzione per quel "req_OnReadyStateChange"?

dal modo in cui sto utilizzando l'oggetto MSXML2.ServerXMLHTTP e questo funziona correttamente. c'è qualche ragione per cui stai usando questa API WinHttp?

esempio con MSXML2.ServerXMLHTTP:

<% 
dim url : url = "http://localhost" 
dim XmlHttp : set XmlHttp = server.createobject("MSXML2.ServerXMLHTTP") 
XmlHttp.onreadystatechange = getRef("doHttpReadyStateChange") 
XmlHttp.open "GET", url, true 
XmlHttp.send() 

sub doHttpReadyStateChange 
    response.write XmlHttp.readyState 
    response.write "<br>" 

    select case XmlHttp.readyState 
     case 0 'UNINITIALIZED 

     case 1 'LOADING 

     case 2 'LOADED 

     case 3 'INTERACTIVE 

     case 4 'COMPLETED 
      response.write "Done" 
    end select 
end sub 
%> 
+0

Sì, ho bisogno di URL finale dopo i thats di reindirizzamento per questo che sto usando WinHttp.WinHttpRequest.5.1. per ulteriori informazioni è possibile controllare http://stackoverflow.com/questions/20358654/serverxmlhttp-request-returing-data-but-not-returning-url-of-final-page-after-30 –

+0

@Dr_Dang ok e hai provato a utilizzare una Sub invece di una funzione per l'evento OnReadyStateChange? – ulluoink

Problemi correlati