Avatar of hankknight
hankknight
Flag for Canada asked on

ASP.NET/VB: Username and password with HttpWebRequest

Using ASP.NET/VB, how can I provide a username and password for basic authentication?
<%@ Page Language="VB" %>
<%@Import namespace="System"%>
<%@Import namespace="System.Web"%>
<%@Import namespace="System.Net"%>
<%@Import namespace="System.Xml"%>
<%@Import namespace="System.IO"%>
<%@Import namespace="System.Text"%>
<%

Dim postString as String = "{}"

Dim webRequest As HttpWebRequest = TryCast(WebRequest.Create("http://example.com/"), HttpWebRequest)
webRequest.USERNAME = "usernamex"
webRequest.PASSWORD = "passwordx"
webRequest.Method = "POST"
webRequest.ContentType = "application/json"
webRequest.ContentLength = postString.Length
webRequest.Accept = "application/json"
Dim requestWriter As New StreamWriter(webRequest.GetRequestStream())
requestWriter.Write(postString)
requestWriter.Close()

%>

Open in new window

Visual Basic.NETASP.NET

Avatar of undefined
Last Comment
Carl Tawn

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Carl Tawn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck