473,320 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

httpwebrequest credentials

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.WindowsImpersonationCont ext
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(IAsyncRes ult asyncResult)
at System.Net.HttpWebRequest.GetResponse() etc, etc..
Nov 18 '05 #1
0 1857

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jamie | last post by:
I'm trying to create a HttpWebRequest object that uses the current logged in users credentials. The site is using Windows Authentication, Anonymous access is turned off. Will the HttpWebRequest...
2
by: Steve Richter | last post by:
I have a page that uses simple HTTP GET to do an ISBN lookup via Amazon.com. The page works when I run it from //localhost. But I have moved it to my godaddy.com shared hoster site, and I get...
1
by: Dave Brown | last post by:
I am attempting to post to a url (https://FakeURL/logon.asp) using the HttpWebRequest class. The response for a succesful post will contain the html for the logon user's default page. We've...
8
by: Dave Brown | last post by:
I am attempting to post to a url (https://FakeURL/logon.asp) using the HttpWebRequest class. The response for a succesful post will contain the html for the logon user's default page. We've...
1
by: mroffey | last post by:
Hi I'm using the code below to post to a web form, but when I run it, i get System.Net.WebException: The operation has timed-out. error Obviously something is wrong, can anyone give me a clue?...
1
by: phil.jacobs | last post by:
Hi there, I am very stuck and have tried everything on this one! I am trying to get to an https website and cannot work out how to logon. When I log on manually, I have to enter username and...
1
by: moo | last post by:
Is there a simple way to get my logon credentials to make my web request work through our proxy server? I tried CredentialCache.DefaultCredentials, but I get nothing back. I can get it to work if I...
2
by: =?Utf-8?B?TGFycnlLdXBlcm1hbg==?= | last post by:
Our WebDev team seems to have found a problem that exposes a bug in .NET 2.0. This problem can be shown when trying to access a WebService using SSL and through a proxy server after using the...
2
by: =?Utf-8?B?TGVuc3Rlcg==?= | last post by:
A C# (.NET 2) application which uses the System.Net.HttpWebRequest object to request a resource over HTTPS is failing following the installation of a new proxy server on our internal network with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.