?
Solved

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

Posted on 2004-10-09
8
Medium Priority
?
360 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 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