IT.COM

[VB.NET] Problem Posting Data

Spaceship Spaceship
Watch
Im trying to post data from a VB.NET application to a web form, but its not passing the fields (it is doing a posting request)

Not all the code, just the code applicable to the problem.

Code:
    Public Client As New System.Net.WebClient
    Public Function HTTPRequest(ByVal URL As String, ByVal postString As String, Optional ByVal Method As String = "POST") As String
        Dim serverResponse() As Byte
        Dim postBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(postString)
        Try
            serverResponse = Me.Client.UploadData(URL, Method, postBytes)
            ' Gets data from server!
        Catch ex As Exception

            MsgBox(ex.Message, MsgBoxStyle.Critical, ex.Source & " Error")
            Exit Function
        End Try
        Dim responseHTML As String = (System.Text.Encoding.ASCII.GetString(serverResponse))
        ' Turns server response(in bytes) into a string(HTML)
        Return responseHTML
    End Function



'Execute function code

Dim postStr As String = "type=100"
Dim submiturl As String = "http://127.0.0.1/posting.php"
        response = HTTPRequest(submiturl, postStr)

Any ideas?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Here is an example that should work.
Need to add some error handling.
PHP:
Imports System.Net
Imports System.IO

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim web_post As WebClient
        Dim byt_param As Byte()
        Dim byt_data As Byte()
        Dim str_response As String

        web_post = New WebClient
        ' add useful headers
        web_post.Headers.Add("Content-Type", "application/x-www-form-urlencoded")

        byt_param = System.Text.Encoding.ASCII.GetBytes("p=test&vc=&fr=yfp-t-501&toggle=1&cop=mss&ei=UTF-8&fp_ip=BE")
        byt_data = web_post.UploadData("http://search.yahoo.com/search", "POST", byt_param)

        str_response = System.Text.Encoding.ASCII.GetString(byt_data)

        MsgBox(str_response) ' receive the HTML back
        web_post.Dispose()

    End Sub
 
1
•••
thanks :)

heh, just happens i got home and checked the post right after you posted :)
 
0
•••
Edit: got it working
 
Last edited:
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back