What's new

.NET HttpWebRequest with Basic auth

S

SynK HD

Grizzled Veteran Seasoned Veteran Chatty Kathy
Messages
1,124
Reaction score
284
I need to give a User + Pass to let the program access my website. It is a .htaccess and .htpassword authentication.
Dim request1 As WebRequest = System.Net.HttpWebRequest.Create(~URL HERE~:" + strText)
Dim response5 As System.Net.HttpWebResponse = request1.GetResponse()
I need to know how to get the above code to access the website URL and give a User + Pass. I'm very new to .NET so any help would be gratefully appreciated.
 
A

AnonLobbies

האחד והיחיד
Messages
297
Reaction score
134
Your using vb right?
 
A

AnonLobbies

האחד והיחיד
Messages
297
Reaction score
134
Can, i get the actual website then i could show you how to do this. I need to know if its using http post or get and see how the user and password parameters are specified. If you send me the website url i should be able to find what i need and give you a code sample.
 
I

imGol2den

Life Goes On!
Messages
1,059
Reaction score
469
C# Easily converatble
Set the website up to be plain text.
WebClient webClient = new WebClient();
if(webClient.DownloadString("URL").Contains(username.ToLower() + password.ToLower()))
{
//go ahead etc
}

If my username was XeXGolden and password poopy.. the website format would be like...
xexgoldenpoopy

NVM
 
A

AnonLobbies

האחד והיחיד
Messages
297
Reaction score
134
C# Easily converatble
Set the website up to be plain text.
WebClient webClient = new WebClient();
if(webClient.DownloadString("URL").Contains(username.ToLower() + password.ToLower()))
{
//go ahead etc
}

If my username was XeXGolden and password poopy.. the website format would be like...
xexgoldenpoopy

Not even close. The above tries to navigate to a website named "URL" and then looks at the content of the web page returned to see if it contains username+password.

If you want to try to log into a website via code you need to pass the user and password as parameters to the website.

For example if the website used a http get protocol (which it most likely does not because then you can see the user and password on the url) the format would be:

Http://somewebite.com?user=username&password=password

The trick is to determine what the parameter names are. In the above the names are user and password.
 
I

imGol2den

Life Goes On!
Messages
1,059
Reaction score
469
Not even close. The above tries to navigate to a website named "URL" and then looks at the content of the web page returned to see if it contains username+password.

If you want to try to log into a website via code you need to pass the user and password as parameters to the website.

For example if the website used a http get protocol (which it most likely does not because then you can see the user and password on the url) the format would be:

Http://somewebite.com?user=username&password=password

The trick is to determine what the parameter names are. In the above the names are user and password.

No ik i was wrong.. lol i was doing something completely different... look at src for website
 
A

AnonLobbies

האחד והיחיד
Messages
297
Reaction score
134
No ik i was wrong.. lol i was doing something completely different... look at src for website

Ok then. Just making sure you were aware. Also so he dosen't mess up and try to use that code.
 
I

imGol2den

Life Goes On!
Messages
1,059
Reaction score
469
Ok then. Just making sure you were aware. Also so he dosen't mess up and try to use that code.

Its pretty obvious that its wrong.. If you look at page source for it then youll see...
I made a kv ban/unbanned checker and I need to do this when logging xbox.com
 
M

Mr Chip53

Enthusiast
Messages
582
Reaction score
200
I need to give a User + Pass to let the program access my website. It is a .htaccess and .htpassword authentication.
Dim request1 As WebRequest = System.Net.HttpWebRequest.Create(~URL HERE~:" + strText)
Dim response5 As System.Net.HttpWebResponse = request1.GetResponse()
I need to know how to get the above code to access the website URL and give a User + Pass. I'm very new to .NET so any help would be gratefully appreciated.

If you haven't figured this out I have this code from one of my projects I was working on a while back.

Code:
Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(url)
			request.Method = method
			Dim postData = data
			Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
			request.ContentType = "application/x-www-form-urlencoded"
			request.ContentLength = byteArray.Length
			Dim dataStream As Stream = request.GetRequestStream()
			dataStream.Write(byteArray, 0, byteArray.Length)
			dataStream.Close()
			Dim response As WebResponse = request.GetResponse()
			dataStream = response.GetResponseStream()
			Dim reader As New StreamReader(dataStream)
			Dim responseFromServer As String = reader.ReadToEnd()
			reader.Close()
			dataStream.Close()
			response.Close()
			Return (responseFromServer)

Slap that in a try{}catch{} and slap the try-catch in a function have the function request ByVal all strings named:
method(It will either be POST or GET)​
data(The post or get data to be sent)​
url(The website URL)​
So i would run function logIn("http://myurl.com/form.html", "username=MyUsername&pass=MyPass", "POST")
it will return the webpage in html format, you may want to download the add-on Tamper Data for firefox. With this add-on you can see what form item names are(EX: 'pass=MyPass' we know its pass= because in the HTML code the password box would be given the name pass. Although, since you have your stuff setup in the .htaccess file I honestly dont know if this would work. If you need any help just holla
 
Top Bottom