Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Basic authentication Fails

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kpg* - 05 Mar 2008 16:46 GMT
Hi all,

In a web service I make a call to a remote server using
basic authentication.

On my development machine it works fine, but on the production
server I get an exception:

"The request was aborted: The request was canceled."

when I make this call:

Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

The request (as far as I can tell) is not making it to the
remote server.  If I don't add the basic auth credentials
then the remote server does respond with an authorization
failure, as I would expect.

What I don't understand is why its acting different on the
development (it works) and production (it fails) boxes.

I'm sure its some security setting on the server (2003 Standard)
that is not on development (xml pro).

Any Ideas?

kpg

Here is the code:

Private Function doRequest(ByVal sURL As String, ByVal sMethod As String,
Optional ByVal sData As String = "", Optional ByVal UserName As String =
"", Optional ByVal Password As String = "") As String

       Dim sResponse As String = ""

       Try

           Dim myWebRequest As WebRequest = WebRequest.Create(sURL)

           If UserName.Length <> 0 Then
               Dim credCache As CredentialCache = New CredentialCache()
               credCache.Add(myWebRequest.RequestUri, "Basic", New
NetworkCredential(UserName, Password))
               myWebRequest.Credentials = credCache
           End If

           myWebRequest.Method = sMethod.ToUpper
           myWebRequest.ContentType = "application/x-www-form-urlencoded"

           If myWebRequest.Method = "POST" Then
               Dim byteArray As Byte() = Encoding.UTF8.GetBytes(sData)
               ' Set the 'ContentLength' property of the WebRequest.
               myWebRequest.ContentLength = byteArray.Length

               Dim myRequestStream As Stream =
myWebRequest.GetRequestStream()
               myRequestStream.Write(byteArray, 0, byteArray.Length)
               ' Close the Stream object.
               myRequestStream.Close()
           Else
               Throw New Exception("Method must be POST")
           End If

           ' Assign the response object of 'WebRequest' to a
'WebResponse' variable.
           Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

           Dim myResponseStream As Stream =
myWebResponse.GetResponseStream()
           Dim streamRead As New StreamReader(myResponseStream)
           Dim readBuff(256) As [Char]

           Dim count As Integer = streamRead.Read(readBuff, 0, 256)
           While count > 0
               Dim outputData As New [String](readBuff, 0, count)
               sResponse &= outputData
               count = streamRead.Read(readBuff, 0, 256)
           End While

           ' Close the Stream Object.
           myResponseStream.Close()
           streamRead.Close()

           ' Release the HttpWebResponse Resource.
           myWebResponse.Close()

       Catch wex As WebException
           sResponse = buildErrorResponse(wex.Message)
       End Try

       WriteToLog("Exit doRequest")

       Return sResponse

   End Function
bruce barker - 05 Mar 2008 18:16 GMT
go to the server and use IE to test if connection works. usually servers are
blocked from accessing remote sites. are you using a proxy?

-- bruce (sqlwork.com)

> Hi all,
>
[quoted text clipped - 93 lines]
>
>     End Function
kpg* - 05 Mar 2008 18:23 GMT
I love answering my own questions.  It makes me feel smart.

I changed this:

Dim myWebRequest As WebRequest = WebRequest.Create(sURL)

to this:

Dim myWebRequest As HttpWebRequest = HttpWebRequest.Create(sURL)
myWebRequest.KeepAlive = False

and it works on the production server now.

I don't recall why I originally used WebRequest insted of
HttpWebrequest, but WebRequest does not expose the keepalive
property.

however...

Is the reason this works becuase the 2003 server box has
a differnet default timeout than my xml pro box?

Even so, without basic auth the request went through, so
hwat's different with basic auth?

As you can see, I don't understand why this works...

kpg
kpg* - 05 Mar 2008 18:28 GMT
> my xml pro box

I seem to keep typing xml pro.

I mean to say 'XP Pro'

geez...

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.