Novice Question About Webclient

  • Thread starter Thread starter Flashster
  • Start date Start date
F

Flashster

I'm a beginner so please be gentle.....

I want to (if its possible) post information to a web based form from my
windows form app and receive the resulting data from the web page.

The web forms code appears to be in javascript (not sure if that is
relevent).

I have tried, as a test, using the example code (see below), but the only
data I get back is the actual web page the data is on, without the resulting
data (as if the page is just reloading). Is this something I am doing wrong
(likely) or prehaps a restriction of the web site not allowing remote
submittions? The web form itself only requires a single field to be input.


The code I have tried:

Dim uriString As String

Console.Write(ControlChars.Cr + "Please enter the URI to post data to{for
example, http://www.contoso.com} : ")

uriString = Console.ReadLine()

' Create a new WebClient instance.

Dim myWebClient As New WebClient

Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted to
the URI {0}:", uriString)

Dim postData As String = Console.ReadLine()

myWebClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")

' Apply ASCII Encoding to obtain the string as a byte array.

Dim byteArray As Byte() = Encoding.ASCII.GetBytes(postData)

Console.WriteLine("Uploading to {0} ...", uriString)

' Upload the input string using the HTTP 1.0 POST method.

Dim responseArray As Byte() = myWebClient.UploadData(uriString, "POST",
byteArray)

' Decode and display the response.

Console.WriteLine(ControlChars.Cr + "Response received was :{0}",
Encoding.ASCII.GetString(responseArray))
 
Its ok - worked it out. I wasn't naming the input fields so the form was
getting confused....rather like me.

Now I just need to work out how to grab the data out of the HTML .....
 
Done that too - used regular expressions.


Flashster said:
Its ok - worked it out. I wasn't naming the input fields so the form was
getting confused....rather like me.

Now I just need to work out how to grab the data out of the HTML .....
 
Hi, good you found the answer. But maybe you can post some sample code, so
that anyone else who ever needs it doesn't get to "frustrated" when he/she
starts searching google and finds your post and then thinks he has found his
answer only to realize when he reads the post it doesn't help him out.

The ng thanks you in advance :-)

Greetz Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top