Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag 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

ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial