UploadString (Post method) in VB.NET not working

I am trying to send 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 p.php:

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

so when I run the VB.NET application, it just calls p.php (GET), but POST does not work. I tried everything. Configured p.php to other servers, checked other variables in php ($ _REQUEST), used UploadString (URL, "POST", "bla = test"), used PERL, ASP .. nothing.

I am using the .NET Framework 3.5 Any ideas on how to send data using vb.net?

0
source share
1 answer

I figured it out 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)
+6
source

Source: https://habr.com/ru/post/1754691/


All Articles