473,788 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebClient VB Post Data to Webpage

Ben
Hi

I have the two funcions below, login_web that posts data to a webpage and
fcn_parseviewst ate that parses the viewstate data for the post.

I have a problem with the strPostData, I have been testing this using a HTTP
Debugging Proxy, when I post the page manually using a browser it posts the
below data and is successful, if I copy this data into strPostData and post
it using the code below it posts successfully:
strPostData =
"__VIEWSTATE=dD w0NzU3NTEyMjk7O z4eJhsIFXbxP7On 1dC%2BEy1wFpRZK g%3D%3D&txtCmd= &txtData=INSERT +INTO+tblMatter s+%28matterdesc ription%29+VALU ES+%28%27descri ption%27%29&pos t=Button"

Broken Down into:
__VIEWSTATE=dDw 0NzU3NTEyMjk7Oz 4eJhsIFXbxP7On1 dC%2BEy1wFpRZKg %3D%3D
txtCmd=
txtData=INSERT+ INTO+tblMatters +%28matterdescr iption%29+VALUE S+%28%27descrip tion%27%29
post=Button

BUT
My when my program posts the data normally (without copying the above data)
program posts the data in this format:
......
txtData=INSERT INTO tblMatters (MatterDescript ion) VALUES ('TESTING')
......

This means that the post fails...

How can i convert INSERT INTO tblMatters (MatterDescript ion) VALUES
('TESTING') TO
INSERT+INTO+tbl Matters+%28matt erdescription%2 9+VALUES+%28%27 description%27% 29

Thanks

B

Private Function web_login() As Boolean
On Error GoTo err_web_login

Dim strURL As String

Dim strPostData As String

Dim byteResponse() As Byte

Dim i As Integer

Dim strViewState As String

strURL = strHttpLocation & "sync.aspx?u=si monfinn&p=1234"

REM ** Download Viewstate Data

byteResponse = gobjWebClient.D ownloadData(str URL)

strViewState = System.Text.Enc oding.ASCII.Get String(byteResp onse)

strViewState = fcn_ParseViewSt ate(strViewStat e)

'strPostData = "VIEWSTATE= " & strViewState & "&txtCmd=&txtDa ta=" & "INSERT
INTO tblMatters (MatterDescript ion) VALUES ('TESTING')" & "&post=Butt on"

strPostData = "VIEWSTATE= " & strViewState & "&txtCmd=&txtDa ta=" & "INSERT
INTO tblMatters (MatterDescript ion) VALUES ('TESTING')" & "&post=Butt on"

gobjWebClient.H eaders.Add("Con tent-Type",
"applicatio n/x-www-form-urlencoded")

byteResponse = gobjWebClient.U ploadData(strUR L, "POST",
System.Text.Enc oding.ASCII.Get Bytes(strPostDa ta))

TextBox1.Text = System.Text.Enc oding.ASCII.Get String(byteResp onse)

web_login = True

REM ** err_web_login

Exit Function

err_web_login:

'Return Error

web_login = False

End Function

Private Function fcn_ParseViewSt ate(ByVal strSource As String) As String

REM ** Declarations

Dim intViewStatePos ition As Integer

Dim intViewStateEnd Position As Integer

REM ** Parse Viewstate Start Posision + 20 Chars for End

intViewStatePos ition = strSource.Index Of("__VIEWSTATE ") + 21

REM ** Parse Viewstate End Posision

intViewStateEnd Position = Mid(strSource, intViewStatePos ition).IndexOf( "
/") - 1

REM ** Return Viewstate only

fcn_ParseViewSt ate = Mid(strSource, intViewStatePos ition,
intViewStateEnd Position)

End Function
Nov 21 '05 #1
2 4554
You can use System.Web.Http Utility.HtmlEnc ode Shared
function to produce the string ready to be transmitted
via Http

-----Original Message-----
Hi

I have the two funcions below, login_web that posts data to a webpage andfcn_parseviews tate that parses the viewstate data for the post.
I have a problem with the strPostData, I have been testing this using a HTTPDebugging Proxy, when I post the page manually using a browser it posts thebelow data and is successful, if I copy this data into strPostData and postit using the code below it posts successfully:
strPostData =
"__VIEWSTATE=d Dw0NzU3NTEyMjk7 Oz4eJhsIFXbxP7O n1dC% 2BEy1wFpRZKg%3D %
3D&txtCmd=&txtD ata=INSERT+INTO +tblMatters+%
28matterdescrip tion%29+VALUES+ %28%27descripti on%27%
29&post=Button "
Broken Down into:
__VIEWSTATE=dD w0NzU3NTEyMjk7O z4eJhsIFXbxP7On 1dC% 2BEy1wFpRZKg%3D %3DtxtCmd=
txtData=INSERT +INTO+tblMatter s+%28matterdesc ription% 29+VALUES+%28%2 7description%27 %29post=Button

BUT
My when my program posts the data normally (without copying the above data)program posts the data in this format:
......
txtData=INSE RT INTO tblMatters (MatterDescript ion) VALUES ('TESTING')......

This means that the post fails...

How can i convert INSERT INTO tblMatters (MatterDescript ion) VALUES('TESTING') TO
INSERT+INTO+tb lMatters+%28mat terdescription% 29+VALUES+% 28%27descriptio n%27%29
Thanks

B

Private Function web_login() As Boolean
On Error GoTo err_web_login

Dim strURL As String

Dim strPostData As String

Dim byteResponse() As Byte

Dim i As Integer

Dim strViewState As String

strURL = strHttpLocation & "sync.aspx?u=si monfinn&p=1234"

REM ** Download Viewstate Data

byteResponse = gobjWebClient.D ownloadData(str URL)

strViewState = System.Text.Enc oding.ASCII.Get String (byteResponse)
strViewState = fcn_ParseViewSt ate(strViewStat e)

'strPostData = "VIEWSTATE= " & strViewState & "&txtCmd=&txtDa ta=" & "INSERTINTO tblMatters (MatterDescript ion) VALUES ('TESTING')" & "&post=Butt on"
strPostData = "VIEWSTATE= " & strViewState & "&txtCmd=&txtDa ta=" & "INSERTINTO tblMatters (MatterDescript ion) VALUES ('TESTING')" & "&post=Butt on"
gobjWebClient. Headers.Add("Co ntent-Type",
"applicatio n/x-www-form-urlencoded")

byteResponse = gobjWebClient.U ploadData(strUR L, "POST",
System.Text.En coding.ASCII.Ge tBytes(strPostD ata))

TextBox1.Tex t = System.Text.Enc oding.ASCII.Get String (byteResponse)
web_login = True

REM ** err_web_login

Exit Function

err_web_logi n:

'Return Error

web_login = False

End Function

Private Function fcn_ParseViewSt ate(ByVal strSource As String) As String
REM ** Declarations

Dim intViewStatePos ition As Integer

Dim intViewStateEnd Position As Integer

REM ** Parse Viewstate Start Posision + 20 Chars for End

intViewStatePo sition = strSource.Index Of("__VIEWSTATE ") + 21
REM ** Parse Viewstate End Posision

intViewStateEn dPosition = Mid(strSource, intViewStatePos ition).IndexOf( "/") - 1

REM ** Return Viewstate only

fcn_ParseViewS tate = Mid(strSource, intViewStatePos ition,intViewStateEn dPosition)

End Function
.

Nov 21 '05 #2
Ben
Thanks

That worked perfectly

B
"Sergey Poberezovskiy" <an*******@disc ussions.microso ft.com> wrote in
message news:3b******** *************** *****@phx.gbl.. .
You can use System.Web.Http Utility.HtmlEnc ode Shared
function to produce the string ready to be transmitted
via Http

-----Original Message-----
Hi

I have the two funcions below, login_web that posts data

to a webpage and
fcn_parseview state that parses the viewstate data for

the post.

I have a problem with the strPostData, I have been

testing this using a HTTP
Debugging Proxy, when I post the page manually using a

browser it posts the
below data and is successful, if I copy this data into

strPostData and post
it using the code below it posts successfully:
strPostData =
"__VIEWSTATE= dDw0NzU3NTEyMjk 7Oz4eJhsIFXbxP7 On1dC%

2BEy1wFpRZKg%3D %
3D&txtCmd=&txtD ata=INSERT+INTO +tblMatters+%
28matterdescrip tion%29+VALUES+ %28%27descripti on%27%
29&post=Button "

Broken Down into:
__VIEWSTATE=d Dw0NzU3NTEyMjk7 Oz4eJhsIFXbxP7O n1dC%

2BEy1wFpRZKg%3D %3D
txtCmd=
txtData=INSER T+INTO+tblMatte rs+%28matterdes cription%

29+VALUES+%28%2 7description%27 %29
post=Button

BUT
My when my program posts the data normally (without

copying the above data)
program posts the data in this format:
......
txtData=INSER T INTO tblMatters (MatterDescript ion)

VALUES ('TESTING')
......

This means that the post fails...

How can i convert INSERT INTO tblMatters

(MatterDescript ion) VALUES
('TESTING') TO
INSERT+INTO+t blMatters+%28ma tterdescription %29+VALUES+%

28%27descriptio n%27%29

Thanks

B

Private Function web_login() As Boolean
On Error GoTo err_web_login

Dim strURL As String

Dim strPostData As String

Dim byteResponse() As Byte

Dim i As Integer

Dim strViewState As String

strURL = strHttpLocation & "sync.aspx?u=si monfinn&p=1234"

REM ** Download Viewstate Data

byteRespons e = gobjWebClient.D ownloadData(str URL)

strViewStat e = System.Text.Enc oding.ASCII.Get String

(byteResponse)

strViewStat e = fcn_ParseViewSt ate(strViewStat e)

'strPostDat a = "VIEWSTATE= " & strViewState

& "&txtCmd=&txtDa ta=" & "INSERT
INTO tblMatters (MatterDescript ion) VALUES ('TESTING')"

& "&post=Butt on"

strPostData = "VIEWSTATE= " & strViewState

& "&txtCmd=&txtDa ta=" & "INSERT
INTO tblMatters (MatterDescript ion) VALUES ('TESTING')"

& "&post=Butt on"

gobjWebClient .Headers.Add("C ontent-Type",
"applicatio n/x-www-form-urlencoded")

byteRespons e = gobjWebClient.U ploadData(strUR L, "POST",
System.Text.E ncoding.ASCII.G etBytes(strPost Data))

TextBox1.Te xt = System.Text.Enc oding.ASCII.Get String

(byteResponse)

web_login = True

REM ** err_web_login

Exit Function

err_web_login :

'Return Error

web_login = False

End Function

Private Function fcn_ParseViewSt ate(ByVal strSource As

String) As String

REM ** Declarations

Dim intViewStatePos ition As Integer

Dim intViewStateEnd Position As Integer

REM ** Parse Viewstate Start Posision + 20 Chars for End

intViewStateP osition = strSource.Index Of("__VIEWSTATE ")

+ 21

REM ** Parse Viewstate End Posision

intViewStateE ndPosition = Mid(strSource,

intViewStatePos ition).IndexOf( "
/") - 1

REM ** Return Viewstate only

fcn_ParseView State = Mid(strSource,

intViewStatePos ition,
intViewStateE ndPosition)

End Function
.

Nov 21 '05 #3

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

Similar topics

0
1283
by: omyek | last post by:
I'm essentially trying to do what a lot of users seem to want when using the above classes, and that's POST to a webpage. Well, I'm golden when it comes to POSTing, I've been able to post to websites using both the webrequest/response and webclient methods. However, the problem I'm running into with both options is I seem to "lose" my connection/session. Let me try to explain a little better. I connect to a website which
0
2051
by: mc kim via .NET 247 | last post by:
What I am trying to is automatic bidding process in Ebay site... WebClient class can uploads form data easily. I have collected ebay url & form data to uploads.. Most of process is quite easy and simple. But ebay webserver send me your password is not valid... But the password is clearly correct.. you can type it at the result page and submit. Then you can see a message - bidding has ended and you are logged in. <- This is the message...
6
12247
by: genc ymeri | last post by:
Hi, We are struggeling to upload a file through a C# webClient into JBoss web server. Meanwhile we are able to upload a file from the webserver itself. The problem is only with C# webClient . The code is pretty simple. string uriString = saveTargetToAddress.Text; string postData = textOutput.Text; try
1
2609
by: Nurchi BECHED | last post by:
Hello, everyone. I am stuck with the following: There is a webpage which contains a webform, which contains text fields, and submits the data from current page to another one. I need to submit the same data to a webpage from a Windows Form.
4
10321
by: Paul J. Lay | last post by:
I am sending and receiving multipart messages using the WebClient UploadData method Method=Post. Everything seems to work well except when the URL contains parameters. For example: http://www.someURL.com?parm1=data1&parm2=data2. I don't believe these paramters are transmitted as part of the URL with the HTTP Post interface. I was under the impression that the WebClient class automatically handled these parameters for POST. The...
0
4089
by: Kumar | last post by:
Hi all, I have the following code which uses WebClient.UploadValues myNameValueCollection.Add("Name", name) myNameValueCollection.Add("Age", age) .............. ............. Dim web As New System.Net.WebClient web.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
3
7590
by: Manuel | last post by:
I have an asp page ("test.asp") that presents the data it receives from a post.When I try the following code, test.asp doesn't return the values (supposedly) posted to it. If I make a web page with a form and the values, test.asp reports them fine. ---------------------------- Dim thePost As String = "Variable1=Value1&Variable2=Value2&Variable3=Value3" Dim thePage As Byte() Dim MyWebClient As New System.Net.WebClient
1
3502
by: Ben | last post by:
Hi I have the code below that I am using to login to my remote webpage. The problem is that it seems to not post the data. I have heard that ViewState can be a problem and that it may be necessary to retrieve the ViewState field and Post it with the data, i have attempted test this by copying the viewstate text out of the source and into the start of the variable strPostData - as you can see commented out.
0
768
by: Mihaly | last post by:
I have a WinForms 1.1 application and I want to post some files on the webserver, using WebClient.UploadFile() method. I try the solution from MSDN site - http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemNetWebClientClassUploadFileTopic1.asp. I creat a ReciveFile.aspx webpage with the content dercribed on this site and I use send the file with this code: WebClient web = new WebClient();...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10373
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10118
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2897
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.