-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: jawa1979
Message 1 in Discussion

Hi friends,


I am using the following function to POST the data to another form through 
HTTPwebRequest. The destination page is protected by windows authentication 
and am passing the proper credentials for the page. The below code is 
working fine for some virtual directories and not working for some. I am 
receiving the following error :
The remote server returned an error: (401) Unauthorized.
Please advice what is causing the problem  and how to fix that.
With the supplied credentials I can able to browse the files through 
browser.


The Content of the function :

     strURI = "http:\\xxxxx.com\testpage.asp"
     Dim bReturn as Boolean = True
     Dim oWebRequest as  HTTPwebRequest
     Dim oWebResponse as  HTTPwebResponse
     Dim oEncoding as UTF8Encoding
     Dim arrBytes as Byte()
     Dim oStream  as Stream
     Dim oStreamReader as StreamReader
     Dim networkCredential As New NetworkCredential("username","password")


     oEncoding = New UTF8Encoding()
     arrBytes = oEncoding.GetBytes(sPostString)
     oWebRequest = Ctype(WebRequest.Create(strURI), HTTPwebRequest)
     oWebRequest.Method = "POST"
     oWebRequest.ContentType = "application/x-www-form-urlencoded"
     oWebRequest.Credentials = networkCredential
     oWebRequest.ContentLength = arrBytes.Length
     oStream = oWebRequest.GetRequestStream()
     oStream.Write (arrBytes,0,arrBytes.Length)
     oStream.Close()

     oWebResponse = oWebRequest.GetResponse()

     If (oWebResponse.StatusCode = HTTPStatusCode.OK )  Then
      oStreamReader = new StreamReader 
(oWebResponse.GetResponseStream,Encoding.ASCII)
      strHTML = oStreamReader.ReadToEnd()
      oStreamReader.Close()
     End If

Bunch of Thanks for the help!
Jawahar

_________________________________________________________________
Screensavers for every mood! http://www.msn.co.in/Download/screensaver/ Jazz 
up your screen!



-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/Bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to