httpwebrequest Vista Error

  • Thread starter Terry Bockover(Legion Boy)
  • Start date
T

Terry Bockover(Legion Boy)

I have used the httpwebrequest object to read an html file as stream from our
web server hosted on an as-400 secured directory. After logging on with the
credentials object it worked fine under XP sp2. When I loaded Vista Business
from latest msdn download on 11/17/2006 I now get unauthorized error message.
Does anyone know what is causing this?

Here is my code which works fine in XP sp2 IE 7 Created in VS 2005 in Visual
Basic Winform Application.

Public Function GetDownloadFile() As Boolean
' Gets file names of members data available from login
' Output is in html with line breaks between links.
Dim fPathName As String
Dim Filecount As Integer
Dim htmlParse As New SetupWizard.HTMLContentParser
fPathName = mydbPath & "Autofileinfo.txt"
'Create File to write contents to
Dim fs As New FileStream(fPathName, FileMode.Create, FileAccess.Write)
Dim s As New StreamWriter(fs)
Dim contentstr As String = ""
Dim credcache As New CredentialCache
Try
Filecount = 0
'Setup arrays to initial values
downloadFiles(0) = "No File"
downloadFiles(1) = "No File"
downloadFiles(2) = "No File"
downloadFiles(3) = "No File"
TextUrl.Clear() ' Clear before each use
' Create a new 'HttpWebRequest' object to the mentioned URL.
Dim myHttpWebRequest As HttpWebRequest =
CType(WebRequest.Create("http://www.members.legion.org/cgi-bin/Userlogin"),
HttpWebRequest)
myHttpWebRequest.UserAgent = "Aim Extreme User"
myHttpWebRequest.PreAuthenticate = True
myHttpWebRequest.Accept = "html/text/xml"
myHttpWebRequest.Method = "Post"
myHttpWebRequest.Credentials = New
NetworkCredential(TextUser.Text, TextPassword.Text)
credcache.Add(myHttpWebRequest.RequestUri, "Kerberos",
myHttpWebRequest.Credentials)
credcache.GetCredential(myHttpWebRequest.RequestUri, "Kerberos")
' The response object of 'HttpWebRequest' is assigned to a
'HttpWebResponse' variable.
Dim myHttpWebResponse As HttpWebResponse =
CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
' Display the contents of the page to the console.
Dim streamResponse As Stream =
myHttpWebResponse.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse)
Dim readBuff(256) As [Char]
Dim count As Integer = streamRead.Read(readBuff, 0, 256)
s.WriteLine(ControlChars.Cr + "The contents of HTML Page are :"
+ ControlChars.Cr)
While count > 0
Dim outputData As New [String](readBuff, 0, count)
' Write file to review later if needed
s.WriteLine(outputData)
TextUrl.Text = TextUrl.Text & outputData
' Check how much read
count = streamRead.Read(readBuff, 0, 256)
End While
streamRead.Close()
streamResponse.Close()
s.Close()
fs.Close()
' Release the response object resources.
myHttpWebResponse.Close()
Catch ex As Exception
LabelMessage.Text = "Error Accessing download file from server:"
& Chr(10) & ex.Message
LabelMessage.Visible = True
errormessage = errormessage & Chr(10) & LabelMessage.Text
ErrorMessageCount = ErrorMessageCount + 1
s.Close()
fs.Close()
Return False
End Try
Try
' Process Kenny's html here
' Load html content to parser return links as array
' Parser only gets links not labels
contentstr = TextUrl.Text
Dim myFileList As ArrayList =
htmlParse.ParseHTMLLinks(contentstr, "")
If myFileList.Count > 0 Then
Filecount = myFileList.Count
Dim i As Integer = 0
For i = 0 To myFileList.Count - 1
downloadFiles(i) = myFileList(i)
Next
End If
If myFileList.Count <= 0 Then
LabelMessage.Text = "Error: File Download Links Unavailable
contact tech support:" & _
Chr(10) & "1-800-860-3100"
LabelMessage.Visible = True
errormessage = errormessage & Chr(10) & LabelMessage.Text
ErrorMessageCount = ErrorMessageCount + 1
Return False
End If
Return True
Catch ex As Exception
LabelMessage.Text = "Error processing file from server:" &
Chr(10) & ex.Message
LabelMessage.Visible = True
errormessage = errormessage & Chr(10) & LabelMessage.Text
ErrorMessageCount = ErrorMessageCount + 1
s.Close()
fs.Close()
Return False
End Try

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top