Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Spht on September 29, 2003, 11:29 AM

Title: Anyone familiar with Wininet in Visual Basic?
Post by: Spht on September 29, 2003, 11:29 AM
I'm having trouble with the InternetOpenUrl function. It works fine when I attempt to connect to a HTTPS page when I specify no header and zero-length. But I always get ERROR_HTTP_HEADER_NOT_FOUND when trying to specifiy a header.

Does anyone have a working sample of using InternetOpenUrl to specifiy the address of a HTTPS page along with a header?

Here is a sample connecting to https://login.passport.com:

InternetOpenUrl(hInternetSession, "https://login.passport.com", vbNullString, 0, INTERNET_FLAG_NO_COOKIES Or INTERNET_FLAG_NO_AUTO_REDIRECT, 0)

hInternetSession being the handle returned by InternetOpen.

That works fine, with vbNullString for lpszHeaders and 0 for dwHeadersLength. However, when trying to specify header, it fails.

Thanks.
Title: Re:Anyone familiar with Wininet in Visual Basic?
Post by: drivehappy on September 29, 2003, 11:41 AM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/httpaddrequestheaders.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/httpaddrequestheaders.asp)

It's not the same function but I believe your header must be terminated with a CrLf.
Title: Somewhat different, but related:
Post by: Adron on September 29, 2003, 01:46 PM
Why not use the ocx?

Add an inet ocx, a multiline text box and a command button and then try this (mostly stolen from VB6 online help):


Option Explicit

Private Sub Command1_Click()
 Inet1.Execute "https://login.passport.com", "GET", , "Accept-Language: sv" & vbCrLf
End Sub

Private Sub Inet1_StateChanged(ByVal State As Integer)
  Dim vtData As Variant ' Data variable.
  Select Case State
  ' ... Other cases not shown.
  Case icError ' 11
     ' In case of error, return ResponseCode and
     ' ResponseInfo.
     vtData = Inet1.ResponseCode & ":" & Inet1.ResponseInfo
  Case icResponseCompleted ' 12
     Dim strData As String
     Dim bDone As Boolean: bDone = False

     ' Get first chunk.
     vtData = Inet1.GetChunk(1024, icString)
     DoEvents

     Do While Not bDone
        strData = strData & vtData
        ' Get next chunk.
        vtData = Inet1.GetChunk(1024, icString)
        DoEvents

        If Len(vtData) = 0 Then
           bDone = True
        End If
     Loop
     Text1.Text = strData
  End Select
End Sub



Changing the language from "sv" to "en" or "de" will produce different outputs, "proving" that you can add that header to the request.
Title: Re:Anyone familiar with Wininet in Visual Basic?
Post by: Spht on September 29, 2003, 03:42 PM
I'll use the OCX for now until I figure out why InternetOpenUrl returns ERROR_HTTP_HEADER_NOT_FOUND. Since I get this error immdiately after calling the function, I take it that this is an error from the DLL - since I specified non-zero for header length, the DLL can not find my header (for some reason). I tried CrLf-terminated headers and null-terminated headers and neither work. And all examples I've found on Google don't use headers.

Thanks.
Title: Re:Anyone familiar with Wininet in Visual Basic?
Post by: Michael on November 01, 2003, 08:47 PM
hey, why dont you have it load the page and headers into a text box that would make it easyer but would cost more ram. He i dont no if i am right i only program for a hobby but maybe my idea will work.
Title: Re:Anyone familiar with Wininet in Visual Basic?
Post by: Skywing on November 01, 2003, 10:13 PM
Quote from: -MichaeL- on November 01, 2003, 08:47 PM
hey, why dont you have it load the page and headers into a text box that would make it easyer but would cost more ram. He i dont no if i am right i only program for a hobby but maybe my idea will work.
Please don't pull up month-old threads like this.