Posting multiple key/value pairs to php file

  • Thread starter Thread starter AndyNakamura
  • Start date Start date
A

AndyNakamura

Guest
I want to fill in a form on a vb.net desktop application and then send the values to a php for that will update a MySQL database.

I can only figure out how to send one key/value pair though.
"message1=" & TextBox1.Text
As in the code blocks below.
I also want to be able to send: "message1=" & TextBox1.Text & "message2=" & TextBox2.Text & "message3=" & TextBox3.Text

Anyone know how to do that?

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim postData As Byte() = Encoding.Default.GetBytes("message1=" & TextBox1.Text) '
sendPost(postData)
End Sub

Private Function sendPost(ByVal p As Byte()) As String
Dim encoding As New UTF8Encoding
Dim byteData As Byte() = p
Dim postReq As HttpWebRequest = HttpWebRequest.Create(url)
postReq.Method = "POST"
postReq.KeepAlive = True
postReq.ContentType = "application/x-www-form-urlencoded"
'postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
postReq.ContentLength = byteData.Length

Dim postreqstream As Stream = postReq.GetRequestStream()
postreqstream.Write(byteData, 0, byteData.Length)
postreqstream.Close()
Dim postresponse As HttpWebResponse
postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
Stop
Dim postreqreader As New StreamReader(postresponse.GetResponseStream())
Return postreqreader.ReadToEnd()
'Stop
End Function

Thanks

Andy

Continue reading...
 
Back
Top