Solved

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

Posted on 2004-10-09
8
355 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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