Solved

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

Posted on 2004-10-09
8
354 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

772 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