473,396 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Form POST

Ben
Hi

I need to design a form that I can programmatically post using this code
from a VB .NET Windows Application:

Dim web As New System.Net.WebClient()

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

Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes("data=MYDATA")
Dim res As Byte() = web.UploadData("strHttpLocation & "sync.aspx", "POST",
d)

Console.Write(System.Text.Encoding.ASCII.GetString (res))
My current form design is like this, the data being posed by an the
asp:button id="post". What changes do I need to make to enable this post
method?

Thanks
B

<HTML>
<HEAD>
<title>sync</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:textbox id="txtCmd" style="Z-INDEX: 101; LEFT: 64px; POSITION:
absolute; TOP: 120px" runat="server" Width="385px">
</asp:textbox>
<asp:textbox id="txtData" style="Z-INDEX: 102; LEFT: 56px; POSITION:
absolute; TOP: 176px" runat="server" Width="384px" Height="288px"
TextMode="MultiLine">
</asp:textbox>
<asp:button id="post" style="Z-INDEX: 103; LEFT: 384px; POSITION: absolute;
TOP: 488px" runat="server" Text="Button" CommandName="POST">
</asp:button>
</form>
</body>
</HTML>

ON CLICK
Private Sub post_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles post.Click

End sub
Nov 19 '05 #1
6 2721
Ben wrote:
Hi

I need to design a form that I can programmatically post using this
code from a VB .NET Windows Application:

Dim web As New System.Net.WebClient()

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

Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes("data=MYDATA")
Dim res As Byte() = web.UploadData("strHttpLocation & "sync.aspx",
"POST", d)

Console.Write(System.Text.Encoding.ASCII.GetString (res))
My current form design is like this, the data being posed by an the
asp:button id="post". What changes do I need to make to enable this
post method?


You should post the page's ViewState as well. Fetch the page first,
parse the hidden field "__VIEWSTATE" and include that in your POST data.

Cheers,

--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #2
Ben
Hi

How what do i need to parse out of the viewstate?

For example:
<input type="hidden" name="__VIEWSTATE" value="dDwxODY1ODY5NDU3O3Q8O2w8=" />
Would I post:
"VIEWSTATE=dDwxODY1ODY5NDU3O3Q8O2w8="
or
"VIEWSTATE=dDwxODY1ODY5NDU3O3Q8O2w8"

Also how to I execute the On Click event of the Post Button?

Thanks

B

"Joerg Jooss" <ne********@joergjooss.de> wrote in message
news:xn***************@msnews.microsoft.com...
Ben wrote:
Hi

I need to design a form that I can programmatically post using this
code from a VB .NET Windows Application:

Dim web As New System.Net.WebClient()

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

Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes("data=MYDATA")
Dim res As Byte() = web.UploadData("strHttpLocation & "sync.aspx",
"POST", d)

Console.Write(System.Text.Encoding.ASCII.GetString (res))
My current form design is like this, the data being posed by an the
asp:button id="post". What changes do I need to make to enable this
post method?


You should post the page's ViewState as well. Fetch the page first,
parse the hidden field "__VIEWSTATE" and include that in your POST data.

Cheers,

--
http://www.joergjooss.de
mailto:ne********@joergjooss.de

Nov 19 '05 #3
Ben wrote:
Hi

How what do i need to parse out of the viewstate?

For example:
<input type="hidden" name="__VIEWSTATE"
value="dDwxODY1ODY5NDU3O3Q8O2w8=" /> Would I post:
"VIEWSTATE=dDwxODY1ODY5NDU3O3Q8O2w8="
or
"VIEWSTATE=dDwxODY1ODY5NDU3O3Q8O2w8"
The former, i.e. the entire string, regardless how funny it looks ;-)

Also how to I execute the On Click event of the Post Button?


You don't. Simply mimic what parameters are passed if the Post Button
was clicked. You can use a debugging proxy like Fiddler
(www.fiddlertool.com) to view the HTTP messages.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #4
Ben
Hi

I have parsed the viewstate and am now posing this data, but this does not
work. I get a response from the server but it has not posted the data.

Any ideas?

Thanks B

strPostData =
"ViewState=dDw0NzU3NTEyMjk7Oz61Iji6mRkWE2+pXtw1ci5 eFtlmFA==@txtData=INSERT
INTO table (fieldname) VALUES ('TESTING')&post=submit"

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

byteResponse = gobjWebClient.UploadData(strURL, "POST",
Encoding.ASCII.GetBytes(strPostData))

TextBox1.Text = System.Text.Encoding.ASCII.GetString(byteResponse)
sync.aspx:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="sync.aspx.vb"
Inherits="myweb.sync"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>sync</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:textbox id="txtCmd" style="Z-INDEX: 101; LEFT: 56px; POSITION:
absolute; TOP: 120px" runat="server"
Width="385px"></asp:textbox><asp:textbox id="txtData" style="Z-INDEX:
102; LEFT: 56px; POSITION: absolute; TOP: 176px" runat="server"
Width="384px" Height="288px"
TextMode="MultiLine"></asp:textbox><asp:button id="post" style="Z-INDEX:
103; LEFT: 384px; POSITION: absolute; TOP: 488px" runat="server"
Text="Button" CommandName="POST"></asp:button>
<asp:Literal id="litResponse" runat="server"></asp:Literal>
</form>
</body>
</HTML>
"Joerg Jooss" <ne********@joergjooss.de> wrote in message
news:xn****************@msnews.microsoft.com...
Ben wrote:
Hi

How what do i need to parse out of the viewstate?

For example:
<input type="hidden" name="__VIEWSTATE"
value="dDwxODY1ODY5NDU3O3Q8O2w8=" /> Would I post:
"VIEWSTATE=dDwxODY1ODY5NDU3O3Q8O2w8="
or
"VIEWSTATE=dDwxODY1ODY5NDU3O3Q8O2w8"


The former, i.e. the entire string, regardless how funny it looks ;-)

Also how to I execute the On Click event of the Post Button?


You don't. Simply mimic what parameters are passed if the Post Button
was clicked. You can use a debugging proxy like Fiddler
(www.fiddlertool.com) to view the HTTP messages.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de

Nov 19 '05 #5
Ben
Hi

I have go this working by looking at the data from the Fiddler

I only seem to have two problems.

Firstly one problem was that the data I was posting was in format below, the
data needed to be in teh format below that:

INSERT INTO tblMatters (matterdescription) VALUES 'description'
INSERT+INTO+tblMatters+%28matterdescription%29+VAL UES+%28%27description%27%29

Is there a quick way to make this conversion?

Also I need to run this application through a proxy server.

Thanks
B

"Ben" <Be*@NoSpam.com> wrote in message
news:uX**************@tk2msftngp13.phx.gbl...
Hi

I have parsed the viewstate and am now posing this data, but this does not
work. I get a response from the server but it has not posted the data.

Any ideas?

Thanks B

strPostData =
"ViewState=dDw0NzU3NTEyMjk7Oz61Iji6mRkWE2+pXtw1ci5 eFtlmFA==@txtData=INSERT
INTO table (fieldname) VALUES ('TESTING')&post=submit"

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

byteResponse = gobjWebClient.UploadData(strURL, "POST",
Encoding.ASCII.GetBytes(strPostData))

TextBox1.Text = System.Text.Encoding.ASCII.GetString(byteResponse)
sync.aspx:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="sync.aspx.vb"
Inherits="myweb.sync"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>sync</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:textbox id="txtCmd" style="Z-INDEX: 101; LEFT: 56px; POSITION:
absolute; TOP: 120px" runat="server"
Width="385px"></asp:textbox><asp:textbox id="txtData" style="Z-INDEX:
102; LEFT: 56px; POSITION: absolute; TOP: 176px" runat="server"
Width="384px" Height="288px"
TextMode="MultiLine"></asp:textbox><asp:button id="post" style="Z-INDEX:
103; LEFT: 384px; POSITION: absolute; TOP: 488px" runat="server"
Text="Button" CommandName="POST"></asp:button>
<asp:Literal id="litResponse" runat="server"></asp:Literal>
</form>
</body>
</HTML>
"Joerg Jooss" <ne********@joergjooss.de> wrote in message
news:xn****************@msnews.microsoft.com...
Ben wrote:
Hi

How what do i need to parse out of the viewstate?

For example:
<input type="hidden" name="__VIEWSTATE"
value="dDwxODY1ODY5NDU3O3Q8O2w8=" /> Would I post:
"VIEWSTATE=dDwxODY1ODY5NDU3O3Q8O2w8="
or
"VIEWSTATE=dDwxODY1ODY5NDU3O3Q8O2w8"


The former, i.e. the entire string, regardless how funny it looks ;-)

Also how to I execute the On Click event of the Post Button?


You don't. Simply mimic what parameters are passed if the Post Button
was clicked. You can use a debugging proxy like Fiddler
(www.fiddlertool.com) to view the HTTP messages.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de


Nov 19 '05 #6
Ben wrote:
Hi

I have go this working by looking at the data from the Fiddler

I only seem to have two problems.

Firstly one problem was that the data I was posting was in format
below, the data needed to be in teh format below that:

INSERT INTO tblMatters (matterdescription) VALUES 'description'
INSERT+INTO+tblMatters+%28matterdescription%29+VAL UES+%28%27descriptio
n%27%29
That's plain URL encoding. There are several ways to do that. Check out
System.Web.HttpUtility or System.Uri.
Also I need to run this application through a proxy server.


HttpWebRequest has a Proxy property... it's all on MSDN.

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: james | last post by:
How can I have a php script send data to a URL as form post data from within the script without creating an actual form in a web page. I am working with an affiliate program (from Affiliateshop)...
1
by: Jeremy Phillips | last post by:
I am trying to build a web form that uses the "POST" method (too much data for GET) to send data to a second form, then displays the response of that form post. The second web form requires...
2
by: | last post by:
Hi everyone, I'm using VS.NET, Framework 1.1, Windows 2000 Server, IIS 5, all the latest patches are installed. Im having this wierd random problem, that I cannot reproduce but it happens...
4
by: Al Cadalzo | last post by:
I'm trying to simulate a form post (i.e. Method="POST"). The FORM POST I'm trying to simulate is similar to this: <FORM NAME=SearchForm METHOD=POST ACTION=Search> <SELECT name="criteriaA" >...
1
by: guoqi zheng | last post by:
I know in webclient class, there is a possibility to post form data to a remote url, but how can I not only just post, I need to redirect user to that page as well. So what I want is just like a...
1
by: rh1200la | last post by:
Hi all...i'm trying to do a form post in my codebehind file using this method: public static string HttpPost(string URI, string Parameters) { System.Net.WebRequest req =...
1
by: John Braham | last post by:
I have a slight wall headbutter which I'm hoping someone will have an idea for (I'd be very grateful!). Basically I'm trying to make a form post to an asp page programatically from within VB.NET...
10
by: eggie5 | last post by:
Is it possible to get a file without using a form post? I want to get the data (bytes) of a file, text or binary, and just save it to a variable. Similar to the post body of a form that has a...
0
by: shlim | last post by:
Currently I'm using VB.Net to perform a http/https multipart form post to a servlet. I'm able to perform the post using HttpWebrequest via GetRequestStream(). However, the servlet returned me with...
0
by: magix | last post by:
Hi, I launched a modal popup window with code like: <script language="javascript"> function modalWin() { if (window.showModalDialog) { window.showModalDialog("MyPage1.asp","MyPopup",...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.