How can I communicate with a webpage on the low level.. (aka using GET, HTTP/1.1, Hos

trend

Centurion
Joined
Oct 12, 2004
Messages
171
Hello, I need to communicate with a webpage to authenticate a user via "Basic" authentication.

If I do this via telnet servername.com 80 here is how the converstation would go..


me:
GET /FooService/basiconly/Service1.asmx HTTP/1.1
Accept: */*
Host: localhost:8100
Connection: Keep-Alive

The server responds with a challenge:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Digest realm="Login_page", nonce="Ny8yLzIwMDIgMzoyNjoyNCBQTQ", opaque="0000000000000000", stale=false, algorithm=MD5, qop="auth"

Then I reply
GET /FooService/basiconly/Service1.asmx HTTP/1.1
Accept: */*
Host: localhost:8100
Authorization: Digest username="test", realm="RassocDigestSample", qop="auth", algorithm="MD5", uri="/FooService/basiconly/Service1.asmx", nonce="Ny8yLzIwMDIgMzoyNjoyNCBQTQ", nc=00000001, cnonce="c51b5139556f939768f770dab8e5277a", opaque="0000000000000000", response="afa30c6445a14e2817a423ca4a143792"





So basically I need to know how to custome make the request and recieve the answers. (I am not talking about getting HTML data.. I am talking about talking directly to the webserver before the HTML data comes into play)


thanks!
Lee
 
Figure it out..

You have to use the:
Imports System.Collections.Specialized.NameValueCollection
library
 
I am not sure if this will help. But a little over a year ago cyclonebri needed to script interaction with a website to gather metrics. I wrote a testbed for him here that utilized System.Net, specifically the HttpWebRequest and HttpWebResponse classes.

Take a look at the class posted in the last response.
 
Very cool!

I did something like:

Visual Basic:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim client As New WebClient
        Dim username As String = "myusername"
        Dim password As String = "mypw"


        Dim bytes = Encoding.ASCII.GetBytes(username & ":" & password)
        client.Headers.Add("Authorization", "Basic " & Convert.ToBase64String(bytes))

        Dim googlelogin = "https://mail.google.com/mail/feed/atom"
        Dim feedStream As Stream = client.OpenRead(googlelogin)
        Dim reader As New StreamReader(feedStream)
        Dim feedAsXml As String = reader.ReadToEnd
        feedStream.Close()

        textbox2.Text = feedAsXml

        End Sub

But the only problem with this is.. I want to open up a new IE window.. so the user can see the results. (If the webpage is downloaded the opened from C:\, the user will not see the pictures or style sheets that were refered too).
So basically I would want the user to end up at:
https://mail.google.com/mail/feed/atom
(as well as logged in via my header.add )

How can I do this?

thanks!

Lee
 
Back
Top