troubleshooting Question

How to force/Manually add authenticaion to POST WebRequest

Avatar of mpdillon
mpdillon asked on
Web Development.NET ProgrammingWeb Services
14 Comments1 Solution229 ViewsLast Modified:
I need to provide authentication for a POST request. I have never done this before so I have been searching for methods to accomplish this.
I have found this method but it did not work. The message I received was 401 Unauthorized.
Dim myCred As New NetworkCredential("USERNAME", "PASSWORD")
        Dim credsCache As New CredentialCache()
        credsCache.Add(New Uri(Uri), "Basic", myCred)
        Dim request As WebRequest = WebRequest.Create(Uri)
        request.Credentials = credsCache

I found other posts indicating that sometimes the authentication has to be forced. I have been trying to get this code to work but I do not know how to declare the AUTHORIZATION
Dim request As WebRequest
Dim credidentials As String = "userName" + ":" + "Password"
Authorization = Convert.ToBase64String(Encoding.[Default].GetBytes(credidentials))  'How do I declare Authorization?
request.Headers("Authorization") = "Basic " + Authorization

How do I declare authorization or how do I "force" authorization?

Thanks,
pat
ASKER CERTIFIED SOLUTION
ste5an
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros