views:

1079

answers:

1

Hi, I am trying to post simple data to some site, in this example to a php file on my local server. My VB.NET Code:

Dim W As New Net.WebClient
Dim A As String = ""

W.Encoding = System.Text.Encoding.UTF8
Dim URL As String = "http://localhost/test/p.php"
A = W.UploadString(URL, "bla=test")

MsgBox(A)

and here the p.php:

<?
print_r($_POST);
echo "\n";
print_r($_GET);
?>

so, when I start the VB.NET App, it just simple calls the p.php (GET) but POST doesnt work. Tried everything. Upladed the p.php to other servers, checked other variables in php ($_REQUEST), used the UploadString(URL,"POST","bla=test), used PERL, ASP.. nothing.

I am using .NET Framework 3.5 Any Ideas how to Post data with vb.net?

+1  A: 

I figured it out on myself:

    Dim W As New Net.WebClient
    Dim NC As New System.Collections.Specialized.NameValueCollection
    NC.Add("test", "TEEEEEST")

    Dim RESP As Byte()
    Dim R As String
    RESP = W.UploadValues("http://localhost/test/p.php", NC)
    R = System.Text.Encoding.ASCII.GetString(RESP)

    MsgBox(R)
qxxx