Webaccess from Console App

peronn

New member
Joined
Aug 1, 2006
Messages
4
Programming Experience
1-3
Hi,

This is my first post here mainly because it's my first large project in vb.net :)

Before I state my problem I wan't to declare that this is i now way a project to make any kind of spambot or equal.

What i wan't help with is that where i work we have a file with customer information that once a week need to be transmitted to an other company that uses that information. They don't have an FTP acces cause then this would not be a problem. The way we do it right now is that someone opens IE and navigates to their webpage, logs in. Then there is a form with one txt-field and one "browse"-button. We then have to press the button, browse for the file and then press ok and then send.

I reckon that this could be done in VB.net (have looked briefly at webcleint class) but is it possible from a console app? And can the above scenario be done at all?

Could anyone please advice me (if it is posible) where to read and look for documentation and examples. I'm not afraid of reading :) and don't need "ready-to-go-code-plz" :). But i don't say no to examples!

I hope someone can answer all or some of the questions!

regards
Per
 
Hello Perron,
Wellcome to the forum ... i hope you will enjoy with us :)
About your question. Yes it is possible to automate all those steps but would you mind to start the application before you start with the question(s)?
We could make this for you but, in that way you will learn nothing and of course know nothing which is not good for the maintenance of the application. Mens no matter console or windows application start the project and come back with concrete question(s).
Thanks for understanding :)
 
hi Kulrom ant thanks for your answer.

I don't mind starting the application (if by starting you mean start coding). As i (tried) to say in my first post im more intereset in learning how to do it than just copy-paste.

So far i've tested to see if i can get anything from the webpage and i have (this is using webclient) gotten back the "source" from some webpages but when i try this on the current page i get error (401). I opened the page in IE to see what actually happens. The first thing is that a pop-up wants me to press ok regarding a certification and when i press OK here i get promted with yet another popup but this one is for the actual loggin. The popup looks like a windows standard one.

When I have logged in here i get to the form that is described in my first post and cand browse for the file and submit it.

More questions (the first one not so conrete :)).

Is it still possible to do in regards to the first popup being one to validate/confirm a certificate and the login not beeing a form but a popup?

How can i "capture" the popup and "find" the ok button so that i can press it?

Testing different things as i write this so the questions might be more specific.

P
 
Hi again,

I have moved on to try more of webrequest and have pasted the code below. When i run the code and try to acces the page (at the moment i'm just printing the response to a txtbox to see if i can do anything at al :)) i still get the error 401 unauthorised. I can understand why but not how to avoid it..


Dim myRequest As WebRequest = WebRequest.Create(txtAdress.Text)

'This is where i get the error
Dim myResponse As WebResponse = myRequest.GetResponse()

Dim data As Stream
data = myResponse.GetResponseStream
Dim reader As New StreamReader(data)
Dim s As String = reader.ReadToEnd()
txtText.Text = s
Data.Close()
reader.Close()


 
So I will continue to post here and see if someone can help me :)

I have gotten a little further no and actually made the code login to the webpage. But now i'm stuck in getting it to fill in the form and submit it.

The form is just one txtbox and a submit button. Weel there is a Browse-button to but i guess i don't have to use that. I reckon that i could just enter the file name (path) as a value into the txtFilepath and then submit the form. But im yet to figure out how.

This is what i'ge got so far...

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
 
' Initialize the WebRequest for testing purposes i collect the adress from a txtAdress box
Dim myRequest As WebRequest = WebRequest.Create(txtAdress.Text)
'Username and Password for the webpage
myRequest.Credentials = New NetworkCredential("UsrName", "Psw")
' Return the response. 
Dim myResponse As WebResponse = myRequest.GetResponse()
 
Dim data As Stream
data = myResponse.GetResponseStream
Dim reader As New StreamReader(data)
Dim s As String = reader.ReadToEnd()
'I print the response to see that i could get in
txtText.Text = s
data.Close()
reader.Close()
 
myResponse.Close()
End Sub

My guess (and hope) is that there is something like what i do with the username and password for passing along the filepath and submit "action" but i still haven't found anything.

Any help i appriciated.

regards
P


 

Latest posts

Back
Top