Solved

how do i separate name/value pairs in http post data

Posted on 2004-10-09
8
353 Views
Last Modified: 2010-08-05
i have a vb.net app, using httpwebresponse et al, that automates posting data from html forms to a php script.
the data is currently posted to a noddy php script that just echoes the _POST variables.
using ie to post the data from a form i can see the name/value pairs like this:

name1=value1&name2=value2

but if i build the request by hand in vb the name/value pairs run together and aren't separate, and count(_POST) is zero:

name1=value1name2=value2

the code i'm using to build the postdata string (which is, of course, encoded before posting) is:

<code>
dim postdata as string
postdata = name1.text & chrw(63) & value1.text
postdata = postdata & vbcr & name2.text & chrw(63) & value2.text
...
</code>

what am i doing wrong?
i may be being a bit dim, but i can't find any hints in the help.
mtia,
porky.

0
Comment
Question by:porkygoodness
  • 4
  • 2
8 Comments
 
LVL 5

Expert Comment

by:M256
ID: 12268770
Hi porkygoodness,

Try this:

<code>
dim postdata as string
postdata = name1.text & "=" & value1.text
postdata = postdata & "&" & name2.text & "=" & value2.text
postdata = postdata & "&" & name3.text & "=" & value3.text
...
</code>

Matthew
0
 
LVL 1

Author Comment

by:porkygoodness
ID: 12269550
hmm.

i tried that already, but no dice.

i'll try it again.

thanks,
porky.

0
 
LVL 1

Author Comment

by:porkygoodness
ID: 12269563
the ampersands and explicit equals signs don't work.

the displayed string from the php looks right now, but count(_POST) is still zero.

good guess, but no points.

thanks,
stephen.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:porkygoodness
ID: 12269740
ok, perhaps it's not the separator after all.
here's the code. strUrl is the url and strData is the postdata.

<code>
Dim myRequest As HttpWebRequest = CType(WebRequest.Create(strUrl), HttpWebRequest)
Dim myEncoder As New ASCIIEncoding
Dim ByteStream As Byte() = myEncoder.GetBytes(strData)
myRequest.Method = "POST"
myRequest.ContentLength = ByteStream.Length
Try
 Dim mySendStream As Stream = myRequest.GetRequestStream()
 mySendStream.Write(ByteStream, 0, ByteStream.Length)
 '...
Catch
 MsgBox(Err.Number.ToString & " - " & Err.Description)
End Try
</code>

i guess right now i'm pretty much a script kiddy as far as vb goes.
this is mostly copied from the help.
did i miss something?
thanks,
porky.


0
 
LVL 1

Accepted Solution

by:
porkygoodness earned 0 total points
ID: 12269785
found it.
i wasn't setting the ContentType.

  myRequest.ContentType = "application/x-www-form-urlencoded"

thanks for providing a forum for me to work this out.
regards,
stephen.
0
 
LVL 5

Expert Comment

by:M256
ID: 12288053
I'm delighted you figured it out.
You may want to post a question in Community Support to ask for your points to be refunded.
http://www.experts-exchange.com/Community_Support/

Matthew
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now