Solved

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

Posted on 2004-10-09
8
352 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

22 Experts available now in Live!

Get 1:1 Help Now