Valhalla Legends Forums Archive | Visual Basic Programming | Anyone familiar with Wininet in Visual Basic?

AuthorMessageTime
Spht
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.
September 29, 2003, 4:29 PM
drivehappy
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.
September 29, 2003, 4:41 PM
Adron
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):

[code]
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
[/code]


Changing the language from "sv" to "en" or "de" will produce different outputs, "proving" that you can add that header to the request.
September 29, 2003, 6:46 PM
Spht
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.
September 29, 2003, 8:42 PM
-MichaeL-
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.
November 2, 2003, 2:47 AM
Skywing
[quote author=-MichaeL- link=board=31;threadid=2885;start=0#msg26920 date=1067741250]
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.
[/quote]
Please don't pull up month-old threads like this.
November 2, 2003, 4:13 AM

Search