httpwebrequest credentials

G

Guest

I am having a problem communicating with a remote server (on intranet) using
the httpwebrequest object. We have used the object to communicate with other
machines previously, but this time we must actually pass along the windows
authentication credentials.

Our Setup/Problem:
-- All internal servers
-- Cannot use anonymous/basic authentication...all use Integrated NT auth
-- Must use default credentials (cannot specify username/password for
credentialcache, as we must use the person who is logged on to machine)
-- We can successfully use impersonation to access Active Directory
-- Our httpwebrequest to the other internal servers works fine when run on
the same machine(we use impersonation)
-- When someone else tries to run same page on the server from a browser on
another machine, they get a (401) Unauthorized message

Below is part of the code behind that is making the request, the error
occurs in the second-to-last line (the getresponsestream) Thanks for any
help!!

-------------------------------------------------------------
Dim postData As String
Dim ReqObj As HttpWebRequest = CType("http://oururl/default.aspx",
HttpWebRequest)

'Impersonate the user and set request credentials
Dim wi As System.Security.Principal.WindowsIdentity
Dim wic As System.Security.Principal.WindowsImpersonationContext
wi = User.Identity
wic = wi.Impersonate()

postData = "variousPostData=123"
ReqObj.Credentials = CredentialCache.DefaultCredentials
ReqObj.Method = "POST"
ReqObj.ContentType = "application/x-www-form-urlencoded"
ReqObj.ContentLength = postData.Length
ReqObj.Timeout = "30000"

Dim writer As StreamWriter = New StreamWriter(ReqObj .GetRequestStream)
writer.Write(postData.ToString)
writer.Close()

Dim ds As New DataSet
ds.ReadXml(ReqObj.GetResponse.GetResponseStream)
wic.Undo()
-------------------------------------------------------

The error stack is as follows:
The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetResponse() etc, etc..
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top