Solved

HTTP Api question

Posted on 2000-04-14
10
644 Views
Last Modified: 2009-12-09
Using the wininet.dll HTTP api, i try to get a webpage but am redirected to a new location and displayed this new link.
How can i find out the url to this new site that i have been redirected to?


Can someone also give me a link to a detailed explanation of the http api calls in the wininet.dll.

thanks
0
Comment
Question by:vbkann
  • 5
  • 3
  • 2
10 Comments
 
LVL 1

Expert Comment

by:ATM
Comment Utility
Here is constants/types and declarations need to use WinSock API,


Private Const WSADescription_Len = 256
Private Const WSASYS_Status_Len = 128
Private Const AF_INET  As Integer = 2
Private Const SOCK_STREAM  As Integer = 1
Private Const INADDR_ANY& = &H0&
Private Const INVALID_SOCKET = &HFFFF&
Private Const FD_SETSIZE As Integer = 64
'--------------------------winsock types--------------------
Private Type WSADATA
        wversion As Integer
        wHighVersion As Integer
        szDescription(0 To WSADescription_Len) As Byte
        szSystemStatus(0 To WSASYS_Status_Len) As Byte
        iMaxSockets As Integer
        iMaxUdpDg As Integer
        lpszVendorInfo As Long
End Type

Private Type linger
        l_onoff As Integer               ' option on/off */
        l_linger As Integer             ' linger time */
End Type

Private Type IN_ADDRBYTE
         s_b1 As Byte
         s_b2 As Byte
         s_b3 As Byte
         s_b4 As Byte
End Type

Private Type IN_ADDRLONG
         s_addr As Long
End Type


Private Type SOCKADDR_IN
        sin_family As Integer
        sin_port As Integer
        sin_addr As IN_ADDRLONG
        sin_zero(7) As Byte
End Type

Private Type SOCKADDR
         sa_family As Integer '/* address family */
         sa_data As String * 14 '/* up to 14 bytes of direct address */
End Type

Private Type HOSTENT
       hName As Long
       hAliases As Long
       hAddrType As Integer
       hLength As Integer
       hAddrList As Long
End Type

Private Type FDSET
    fd_count As Long
    fd_array(FD_SETSIZE) As Long
End Type

Private Type TMEVAL
    tv_sec As Long
    tv_usec As Long
End Type

'--------------------------winsock types--------------------

'--------------------------winsock maps--------------------
Private Declare Function gethostname Lib "wsock32.dll" ( _
                 ByVal hostname$, _
                 ByVal HostLen As Integer) As Long

Private Declare Function WSAGetLastError Lib "wsock32.dll" _
         () As Long
         
Private Declare Function WSAStartup Lib "wsock32.dll" ( _
                 ByVal wVersionRequired&, _
                 lpWSAData As WSADATA) As Long
                 
Private Declare Function WSACleanup Lib "wsock32.dll" ( _
                                     ) As Long
                                     
'--------------------setsockoption----------------------------------------------------
Private Declare Function setsockopt Lib "wsock32.dll" ( _
                 ByVal s As Long, _
                 ByVal level As Long, _
                 ByVal optname As Long, _
                 optval As Any, _
                 ByVal optlen As Long) As Long

'--------------------------------------------------------------------------------------
'-----------------------closesocket--------------------------
Private Declare Function closesocket Lib "wsock32.dll" ( _
                 ByVal lS As Long) As Byte
                 
'------------------------------------------------------------
Private Declare Function htonl Lib "wsock32.dll" ( _
                 ByVal hostlong As Long) As Long


Private Declare Function gethostbyname Lib "wsock32.dll" ( _
                 ByVal hostname As String) As Long


'--------------------socket-----------------------------------------------------------
Private Declare Function socket Lib "wsock32.dll" ( _
                 ByVal sAF As Long, _
                 ByVal sType As Long, _
                 ByVal sProtocol As Integer) As Long
                 
'--------------------socket-----------------------------------------------------------
Private Declare Function bind Lib "wsock32.dll" ( _
                 ByVal sHandle As Long, _
                 sockaddr_name As Any, _
                 ByVal namelen As Long) As Long
                 
Private Declare Function connect Lib "wsock32.dll" ( _
                 ByVal sHandle As Long, _
                 sockaddr_name As Any, _
                 ByVal namelen As Long) As Long
   
Private Declare Function htons Lib "wsock32.dll" ( _
                 ByVal hostushort As Integer) As Integer

Private Declare Function inet_addr Lib "wsock32.dll" ( _
                 ByVal addr As String) As Long
'--------------------------winsock maps--------------------
Private Declare Function FD_ISSET Lib "wsock32.dll" Alias "__WSAFDIsSet" ( _
              ByVal hSocket As Long, _
              fdsArr As FDSET) As Boolean

Private Declare Function recv Lib "wsock32.dll" ( _
                 ByVal hSocket As Long, _
                 ByVal buf As String, _
                 ByVal bufLen As Long, _
                 ByVal flags As Long) As Long
                 
Private Declare Function send Lib "wsock32.dll" ( _
                 ByVal hSocket As Long, _
                 ByVal buf As String, _
                 ByVal bufLen As Long, _
                 ByVal flags As Long) As Long

'---------------------------memory man---------------------
Private Declare Sub RtlMoveMemory Lib "KERNEL32" ( _
                 hpvDest As Any, _
                 ByVal hpvSource&, _
                 ByVal cbCopy&)
'---------------------------memory man---------------------


Private Declare Function selectX Lib "ws2_32.dll" Alias "select" ( _
    ByVal hSocket As Long, _
    fdsArr As Any, _
    ByVal null1 As Long, _
    ByVal null2 As Long, _
    tmeOut As Any) As Integer
   
' Error returned by Winsock API.
Const SOCKET_ERROR = -1

' Level number for (get/set)sockopt() to apply to socket itself.
Const SOL_SOCKET = 65535      ' Options for socket level.
Const IPPROTO_TCP = 6         ' Protocol constant for TCP.

' option flags per socket
Const SO_DEBUG = &H1&         ' Turn on debugging info recording
Const SO_ACCEPTCONN = &H2&    ' Socket has had listen() - READ-ONLY.
Const SO_REUSEADDR = &H4&     ' Allow local address reuse.
Const SO_KEEPALIVE = &H8&     ' Keep connections alive.
Const SO_DONTROUTE = &H10&    ' Just use interface addresses.
Const SO_BROADCAST = &H20&    ' Permit sending of broadcast msgs.
Const SO_USELOOPBACK = &H40&  ' Bypass hardware when possible.
Const SO_LINGER = &H80&       ' Linger on close if data present.
Const SO_OOBINLINE = &H100&   ' Leave received OOB data in line.
Const SO_RCVTIMEO& = &H1006&
Const SO_SNDTIMEO& = &H1005&

Const SO_DONTLINGER = Not SO_LINGER
Const SO_EXCLUSIVEADDRUSE = Not SO_REUSEADDR ' Disallow local address reuse.

' Additional options.
Const SO_SNDBUF = &H1001&     ' Send buffer size.
Const SO_RCVBUF = &H1002&     ' Receive buffer size.
Const SO_ERROR = &H1007&      ' Get error status and clear.
Const SO_TYPE = &H1008&       ' Get socket type - READ-ONLY.

' TCP Options
Const TCP_NODELAY = &H1&      ' Turn off Nagel Algorithm.

   
Private Declare Function getsockopt Lib "wsock32.dll" (ByVal s As Long, ByVal level As Long, ByVal optname As Long, optval As Any, optlen As Long) As Long

Private Type LINGER_STRUCT
  l_onoff As Integer          ' Is linger on or off?
  l_linger As Integer         ' Linger timeout in seconds.
End Type

In order to find last URL you must to load, parse response code for current request.
200 * final page stop
301 * URL is in Location tag
302 * URL is in Location tag
and so on. refer to RFC 1945 for more info.

To use APIs first create socket

WSAStartup()
socket()
setsockopt() as you need
bind()  to local
connect()  to remote
send()  
recv()
closesocket()
WSAClean()

full source for +100 points.
Hope this help.
0
 
LVL 1

Author Comment

by:vbkann
Comment Utility
I am not using the winsock api to connect via ports. I am using the HTTP api.
Can someone add to my code to tell me how to see what url i am redirected to please.

The header the server returns is as follows:

HTTP/1.1 302 Moved
Date: Mon, 20 Mar 2000 07:47:09 GMT
Server: Apache/1.3.9
Location: http://test.com/test.html
Keep-Alive: timeout=14, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/plain


Which redirects me to "http://test.com/test.html", how can i get the value for this header or how can i see what address i am on via an api call.

This is my HTTP api code that i am using:


Place in a class module

Option Explicit

Private sURL As String
Private sLastError As String
Private sContentType As String
Private lContentLength As Long
Private sLastModified As String
Private sVersion As String
Private sStatusCode As String
Private sStatusText As String
Private sRawHeaders As String
Private sResponseHeaders As String
Private sForwarded As String
Private sServer As String
Private sRequestMethod As String
Private sPragma As String
Public sRequestHeaders As String
Private sUserAgent As String
Private sRequestMethod2 As String

Private hInternetSession As Long
Private hInternetConnect As Long
Private hHttpOpenRequest As Long

Private lMajor As Long
Private lMinor As Long

Event Progress(ProcentDone As Byte, Speed As Currency, Downloaded As Long)

' Initializes an application's use of the Win32 Internet functions
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long

' Use registry access clsSettings.
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0

' Opens a HTTP session for a given site.
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long

' Number of the TCP/IP port on the server to connect to.
Private Const INTERNET_DEFAULT_FTP_PORT = 21
Private Const INTERNET_DEFAULT_GOPHER_PORT = 70
Private Const INTERNET_DEFAULT_HTTP_PORT = 80
Private Const INTERNET_DEFAULT_HTTPS_PORT = 443
Private Const INTERNET_DEFAULT_SOCKS_PORT = 1080

' Type of service to access.
Private Const INTERNET_SERVICE_FTP = 1
Private Const INTERNET_SERVICE_GOPHER = 2
Private Const INTERNET_SERVICE_HTTP = 3

' Opens an HTTP request handle.
Private Declare Function HttpOpenRequest Lib "wininet.dll" Alias "HttpOpenRequestA" (ByVal hHttpSession As Long, ByVal sVerb As String, ByVal sObjectName As String, ByVal sVersion As String, ByVal sReferer As String, ByVal something As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long

' Brings the data across the wire even if it locally cached.
Private Const INTERNET_FLAG_RELOAD = &H80000000

' Sends the specified request to the HTTP server.
Private Declare Function HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" (ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, sOptional As Any, ByVal lOptionalLength As Long) As Integer

' Queries for information about an HTTP request.
Private Declare Function HttpQueryInfo Lib "wininet.dll" Alias "HttpQueryInfoA" (ByVal hHttpRequest As Long, ByVal lInfoLevel As Long, ByRef sBuffer As Any, ByRef lBufferLength As Long, ByRef lIndex As Long) As Integer

' The possible values for the lInfoLevel parameter include:
Private Const HTTP_QUERY_CONTENT_TYPE = 1
Private Const HTTP_QUERY_CONTENT_LENGTH = 5
Private Const HTTP_QUERY_EXPIRES = 10
Private Const HTTP_QUERY_LAST_MODIFIED = 11
Private Const HTTP_QUERY_PRAGMA = 17
Private Const HTTP_QUERY_VERSION = 18
Private Const HTTP_QUERY_STATUS_CODE = 19
Private Const HTTP_QUERY_STATUS_TEXT = 20
Private Const HTTP_QUERY_RAW_HEADERS = 21
Private Const HTTP_QUERY_RAW_HEADERS_CRLF = 22
Private Const HTTP_QUERY_FORWARDED = 30
Private Const HTTP_QUERY_SERVER = 37
Private Const HTTP_QUERY_USER_AGENT = 39
Private Const HTTP_QUERY_SET_COOKIE = 43
Private Const HTTP_QUERY_REQUEST_METHOD = 45

' Add this flag to the about flags to get request header.
Private Const HTTP_QUERY_FLAG_REQUEST_HEADERS = &H80000000

' Reads data from a handle opened by the HttpOpenRequest function.
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer

' Closes a single Internet handle or a subtree of Internet handles.
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

' Queries an Internet option on the specified handle
Private Declare Function InternetQueryOption Lib "wininet.dll" Alias "InternetQueryOptionA" (ByVal hInternet As Long, ByVal lOption As Long, ByRef sBuffer As Any, ByRef lBufferLength As Long) As Integer

' Returns the version number of Wininet.dll.
Private Const INTERNET_OPTION_VERSION = 40

' Contains the version number of the DLL that contains the Windows Internet
' functions (Wininet.dll). This structure is used when passing the
' INTERNET_OPTION_VERSION flag to the InternetQueryOption function.
Private Type tWinInetDLLVersion
  lMajorVersion As Long
  lMinorVersion As Long
End Type

' Adds one or more HTTP request headers to the HTTP request handle.
Private Declare Function HttpAddRequestHeaders Lib "wininet.dll" Alias "HttpAddRequestHeadersA" (ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lModifiers As Long) As Integer

' Flags to modify the semantics of this function. Can be a combination of these values:

' Adds the header only if it does not already exist; otherwise, an error is returned.
Private Const HTTP_ADDREQ_FLAG_ADD_IF_NEW = &H10000000

' Adds the header if it does not exist. Used with REPLACE.
Private Const HTTP_ADDREQ_FLAG_ADD = &H20000000

' Replaces or removes a header. If the header value is empty and the header is found,
' it is removed. If not empty, the header value is replaced
Private Const HTTP_ADDREQ_FLAG_REPLACE = &H80000000

Public Property Get Forwarded() As String

  Forwarded = sForwarded

End Property

Function Connect(Url As String) As Boolean

  Dim vDllVersion As tWinInetDLLVersion
  Dim iRetVal     As Integer
  Dim UrlAddress As String
  Dim UrlServer  As String
 
  If (Left$(Url, 7) = "http://") Then Url = Mid$(Url, 8)
 
  If (InStr(Url, "/") = 0) Then
    UrlServer = Url
    UrlAddress = ""
  Else
    UrlServer = Left$(Url, InStr(Url, "/") - 1)
    UrlAddress = Mid$(Url, Len(UrlServer) + 1)
  End If
 
  sURL = ""
  'Screen.MousePointer = vbHourglass
 
  If CBool(hInternetSession) Then
    InternetQueryOption hInternetSession, INTERNET_OPTION_VERSION, vDllVersion, Len(vDllVersion)
    lMajor = vDllVersion.lMajorVersion
    lMinor = vDllVersion.lMinorVersion
    hInternetConnect = InternetConnect(hInternetSession, UrlServer, INTERNET_DEFAULT_HTTP_PORT, vbNullString, vbNullString, INTERNET_SERVICE_HTTP, 0, 0)
   
    If (hInternetConnect > 0) Then
      hHttpOpenRequest = HttpOpenRequest(hInternetConnect, "GET", UrlAddress, "HTTP/1.0", vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
       
      If CBool(hHttpOpenRequest) Then
        iRetVal = HttpSendRequest(hHttpOpenRequest, vbNullString, 0, 0, 0)

        If iRetVal Then
          'Response headers
          sContentType = RemNull(GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_CONTENT_TYPE))
          lContentLength = Val(GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_CONTENT_LENGTH))
          sLastModified = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_LAST_MODIFIED)
          sVersion = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_VERSION)
          sStatusCode = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_STATUS_CODE)
          sStatusText = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_STATUS_TEXT)
          sRawHeaders = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_RAW_HEADERS)
          sResponseHeaders = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_RAW_HEADERS_CRLF)
          sForwarded = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_FORWARDED)
          sServer = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_SERVER)
          sRequestMethod = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_REQUEST_METHOD)
          sPragma = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_FLAG_REQUEST_HEADERS + HTTP_QUERY_PRAGMA)
          sRequestHeaders = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_FLAG_REQUEST_HEADERS + HTTP_QUERY_RAW_HEADERS_CRLF)
          sUserAgent = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_FLAG_REQUEST_HEADERS + HTTP_QUERY_USER_AGENT)
          sRequestMethod2 = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_FLAG_REQUEST_HEADERS + HTTP_QUERY_REQUEST_METHOD)
          Connect = True
        Else
          'HttpSendRequest failed
          sLastError = "HttpSendRequest failed"
          Connect = False
        End If
      Else
        'HttpOpenRequest failed
        sLastError = "HttpOpenRequest failed"
        Connect = False
        End If
    Else
      'InternetConnect failed
      sLastError = "InternetConnect failed"
      Connect = False
    End If
  Else
    'hInternetSession handle not allocated
    sLastError = "InternetSession failed"
    Connect = False
  End If
 
  sLastError = ""
  sURL = Url
  'Screen.MousePointer = vbDefault

End Function
Public Property Get ContentLength() As Long

  ContentLength = lContentLength
 
End Property
Private Function GetQueryInfo(ByVal hHttpRequest As Long, ByVal iInfoLevel As Long) As String

  ' Purpose    : Retrieves header information
  ' Parameters : HttpRequest handle, label to put information in, and infolevel flag
  ' Return val : Success/Failure
  ' Algorithm  : Calls the HttpQueryInfo function and copies result into label

  Dim sBuffer         As String * 1024
  Dim lBufferLength   As Long

  lBufferLength = Len(sBuffer)
  Call HttpQueryInfo(hHttpRequest, iInfoLevel, ByVal sBuffer, lBufferLength, 0)
  GetQueryInfo = Trim$(sBuffer)

End Function
Function GetFile(ByVal Url As String, Optional sFilename As String, Optional sContent As String, Optional ReadToString As Boolean) As Boolean

  ' Purpose    : Click event for button
  ' Parameters : NA
  ' Return val : NA
  ' Algorithm  : Gets resource identified in sUrl

  Dim bDoLoop             As Boolean
  Dim sReadBuffer         As String * 2048
  Dim sBuffer             As String
  Dim lNumberOfBytesRead  As Long
  Dim Procent             As Byte
  Dim ProcentOld          As Byte
  Dim sUrlAddress         As String
  Dim sUrlServer          As String
  Dim lContentRead        As Long
  Dim timerStart          As Currency
  Dim lLoops              As Byte
  Dim Filenr As Long
  Dim Text As String
 
  If Not Connect(Url) Then
    GetFile = False
    Exit Function
  End If
  DoEvents
 
  If (InStr(sURL, "/") = 0) Then
    sUrlServer = sURL
    sUrlAddress = ""
  Else
    sUrlServer = Left$(sURL, InStr(sURL, "/") - 1)
    sUrlAddress = Mid$(sURL, Len(sUrlServer) + 1)
  End If
 
  On Error GoTo Errorhandler
  sLastError = ""
  lContentRead = 0
  ProcentOld = 0
  DoEvents
  RaiseEvent Progress(0, 0, 0)
  timerStart = Timer
  If (Len(sFilename) = 0) Then ReadToString = True
 
  If ReadToString Then
    sContent = ""
  Else
    If FileExist(sFilename) Then Kill sFilename
    Filenr = FreeFile
    Open sFilename For Binary Access Write As #Filenr
  End If
 
  Do
    lLoops = lLoops + 1
    sReadBuffer = vbNullString
    bDoLoop = InternetReadFile(hHttpOpenRequest, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
 
    If Not ReadToString Then
      Put #Filenr, , Left$(sReadBuffer, lNumberOfBytesRead)
    Else
      sContent = sContent & Left$(sReadBuffer, lNumberOfBytesRead)
    End If
   
    lContentRead = lContentRead + lNumberOfBytesRead
    If (lContentLength > 0) Then
      Procent = Int((lContentRead / lContentLength) * 100)
      If Procent <> ProcentOld Then
        RaiseEvent Progress(Procent, lContentRead / (Timer - timerStart), lContentRead)
        ProcentOld = Procent
      End If
    ElseIf (lLoops >= 10) Then
      lLoops = 0
      RaiseEvent Progress(0, lContentRead / (Timer - timerStart), lContentRead)
    End If
    If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
    DoEvents
  Loop While bDoLoop

  If Not ReadToString Then
    Close #Filenr
  End If
 
  On Error Resume Next
  Call InternetCloseHandle(hHttpOpenRequest)
 
  GetFile = True
  Exit Function
 
Errorhandler:
  On Error Resume Next
  If Not ReadToString Then
    Close #Filenr
  End If
  MsgBox "Error!"

End Function
Function FileExist(FileName As String) As Boolean

  On Error GoTo Errorhandler
 
  Call FileLen(FileName)
  FileExist = True
  Exit Function

Errorhandler:
  FileExist = False

End Function
Public Property Get LastError() As String

  LastError = sLastError

End Property
Public Property Get LastModified() As String

  LastModified = sLastModified
 
End Property

Private Function RemNull(Text As String) As String

  RemNull = Left$(Text, InStr(Text, Chr$(0)) - 1)
 
End Function

Private Sub Class_Initialize()

  hInternetSession = InternetOpen("http protocol", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
  If CBool(hInternetSession) Then
    sLastError = ""
  Else
    sLastError = "InternetOpen failed."
  End If
 
End Sub

Private Sub Class_Terminate()

  On Error Resume Next
  Call InternetCloseHandle(hHttpOpenRequest)
  Call InternetCloseHandle(hInternetSession)
  Call InternetCloseHandle(hInternetConnect)
 
End Sub


0
 
LVL 1

Author Comment

by:vbkann
Comment Utility
Adjusted points from 100 to 200
0
 
LVL 2

Accepted Solution

by:
gelog earned 200 total points
Comment Utility
Hi vbkann,

You already have got a way to retrieve a header information using the HttpQueryInfo WinInet API function or with your own custom function GetQueryInfo. If it is clear to me you just need to call this finction with the HTTP_QUERY_LOCATION flag. For example:

sLocation = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_LOCATION)

Welcome to http://www.vbip.com
0
 
LVL 1

Expert Comment

by:ATM
Comment Utility
Private Function find_moved(ByVal base_url As String)
  Dim Lpos1 As Long
  Dim Lpos2 As Long
  Dim movedURL As String
      Lpos1 = InStr(1, Txt_Response.Text, "Location: ")
      If Lpos1 > 0 Then
         Lpos1 = Lpos1 + 10
         Lpos2 = InStr(Lpos1, Txt_Response.Text, Chr(13))
         If Lpos2 > 0 Then
            movedURL = Mid(Txt_Response.Text, Lpos1, Lpos2 - Lpos1)
            'MsgBox movedURL
            'here movedURL is moved location, now determine is it local or global
            If (UCase(Left(movedURL, 7)) = "HTTP://") Then
              'full-qualified url
            movedURL = Trim(movedURL)
            movedURL = Mid(movedURL, 8, Len(movedURL) - 8)
           find_moved = movedURL
              Exit Function
            Else
              'relative url
              If Left(movedURL, 1) = "/" Then
               'from root path
               Lpos1 = InStr(1, base_url, "/")
               If Lpos1 > 0 Then
                 'yep / position found cut to
                 find_moved = Left(base_url, Lpos1 - 1) & movedURL
                 Exit Function
               Else
                 'nope / position not found append to end
                 find_moved = base_url & movedURL
                 Exit Function
               End If
              Else
               'from default root
               Lpos1 = Len(base_url)
               'find last /
               Do While Lpos1 > 0
                 If Mid(base_url, Lpos1, 1) = "/" Then Exit Do
                 Lpos1 = Lpos1 - 1
               Loop
               '/ not found assume thats start url
               If Lpos1 = 0 Then Lpos1 = Len(base_url) + 1
               'make moved
               find_moved = Left(base_url, Lpos1 - 1) & "/" & movedURL
               Exit Function
              End If
            End If
           
         End If
      End If
     
  find_moved = ""
 
End Function

Txt_Response is a textbox,
base_url is a previous page caused 302 code return.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 1

Author Comment

by:vbkann
Comment Utility
sLocation = GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_LOCATION) would be a perfect way to do it, but i do not know the value for HTTP_QUERY_LOCATION. Do you? Where could i find out and hopefully get all the values for all different headers?
0
 
LVL 2

Expert Comment

by:gelog
Comment Utility
Hi vbkann,

Public Const HTTP_QUERY_MIME_VERSION = 0
Public Const HTTP_QUERY_CONTENT_TYPE = 1
Public Const HTTP_QUERY_CONTENT_TRANSFER_ENCODING = 2
Public Const HTTP_QUERY_CONTENT_ID = 3
Public Const HTTP_QUERY_CONTENT_DESCRIPTION = 4
Public Const HTTP_QUERY_CONTENT_LENGTH = 5
Public Const HTTP_QUERY_CONTENT_LANGUAGE = 6
Public Const HTTP_QUERY_ALLOW = 7
Public Const HTTP_QUERY_PUBLIC = 8
Public Const HTTP_QUERY_DATE = 9
Public Const HTTP_QUERY_EXPIRES = 10
Public Const HTTP_QUERY_LAST_MODIFIED = 11
Public Const HTTP_QUERY_MESSAGE_ID = 12
Public Const HTTP_QUERY_URI = 13
Public Const HTTP_QUERY_DERIVED_FROM = 14
Public Const HTTP_QUERY_COST = 15
Public Const HTTP_QUERY_LINK = 16
Public Const HTTP_QUERY_PRAGMA = 17
Public Const HTTP_QUERY_VERSION = 18
Public Const HTTP_QUERY_STATUS_CODE = 19
Public Const HTTP_QUERY_STATUS_TEXT = 20
Public Const HTTP_QUERY_RAW_HEADERS = 21
Public Const HTTP_QUERY_RAW_HEADERS_CRLF = 22
Public Const HTTP_QUERY_CONNECTION = 23
Public Const HTTP_QUERY_ACCEPT = 24
Public Const HTTP_QUERY_ACCEPT_CHARSET = 25
Public Const HTTP_QUERY_ACCEPT_ENCODING = 26
Public Const HTTP_QUERY_ACCEPT_LANGUAGE = 27
Public Const HTTP_QUERY_AUTHORIZATION = 28
Public Const HTTP_QUERY_CONTENT_ENCODING = 29
Public Const HTTP_QUERY_FORWARDED = 30
Public Const HTTP_QUERY_FROM = 31
Public Const HTTP_QUERY_IF_MODIFIED_SINCE = 32
Public Const HTTP_QUERY_LOCATION = 33
Public Const HTTP_QUERY_ORIG_URI = 34
Public Const HTTP_QUERY_REFERER = 35
Public Const HTTP_QUERY_RETRY_AFTER = 36
Public Const HTTP_QUERY_SERVER = 37
Public Const HTTP_QUERY_TITLE = 38
Public Const HTTP_QUERY_USER_AGENT = 39
Public Const HTTP_QUERY_WWW_AUTHENTICATE = 40
Public Const HTTP_QUERY_PROXY_AUTHENTICATE = 41
Public Const HTTP_QUERY_ACCEPT_RANGES = 42
Public Const HTTP_QUERY_SET_COOKIE = 43
Public Const HTTP_QUERY_COOKIE = 44
Public Const HTTP_QUERY_REQUEST_METHOD = 45
Public Const HTTP_QUERY_REFRESH = 46
Public Const HTTP_QUERY_CONTENT_DISPOSITION = 47

Welcome to http://www.vbip.com
0
 
LVL 2

Expert Comment

by:gelog
Comment Utility
Public Const HTTP_QUERY_AGE = 48
Public Const HTTP_QUERY_CACHE_CONTROL = 49
Public Const HTTP_QUERY_CONTENT_BASE = 50
Public Const HTTP_QUERY_CONTENT_LOCATION = 51
Public Const HTTP_QUERY_CONTENT_MD5 = 52
Public Const HTTP_QUERY_CONTENT_RANGE = 53
Public Const HTTP_QUERY_ETAG = 54
Public Const HTTP_QUERY_HOST = 55
Public Const HTTP_QUERY_IF_MATCH = 56
Public Const HTTP_QUERY_IF_NONE_MATCH = 57
Public Const HTTP_QUERY_IF_RANGE = 58
Public Const HTTP_QUERY_IF_UNMODIFIED_SINCE = 59
Public Const HTTP_QUERY_MAX_FORWARDS = 60
Public Const HTTP_QUERY_PROXY_AUTHORIZATION = 61
Public Const HTTP_QUERY_RANGE = 62
Public Const HTTP_QUERY_TRANSFER_ENCODING = 63
Public Const HTTP_QUERY_UPGRADE = 64
Public Const HTTP_QUERY_VARY = 65
Public Const HTTP_QUERY_VIA = 66
Public Const HTTP_QUERY_WARNING = 67
0
 
LVL 1

Author Comment

by:vbkann
Comment Utility
ok.
I am making a browser using these http commands.

I am having a problems going to the right pages and sending the right referer headers when i go to cgi generated pages though. I am talking about cgi generated pages which change their urls in IE depending on your ip address.

When i get the data from the page, the html code, there is a link to say test.html, i cannot go to this new page as i do not know the address of the page i am on at the moment as it changes. I also need to find the data to send in the referal header (isn't this just the page i am on before i connect to the desired page)Could you please write me a piece of code so that i can get the details i want - i think all i need is the page address but i am not totally sure.

I tried :          MsgBox "HTTP_QUERY_ORIG_URI:" & GetQueryInfo(hHttpOpenRequest, HTTP_QUERY_ORIG_URI) but this did not return anything. Is this what i want to do to get the URL that i am on.

Do you understand what i want - its a little wordy?

0
 
LVL 1

Author Comment

by:vbkann
Comment Utility
i have figured out my last comment, i think. But how can i add a custom header to be sent to the server?

I cannot get this function to work: Private Declare Function HttpAddRequestHeaders Lib "wininet.dll" Alias "HttpAddRequestHeadersA" (ByVal hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lModifiers As Long) As Integer.
Please give me an example of how to add a custom header eg "Test: testing"
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now