UploadString (Post Method) in VB.NET doesn't work

微笑、不失礼 提交于 2019-12-08 12:08:14

问题


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:


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)


来源:https://stackoverflow.com/questions/839158/uploadstring-post-method-in-vb-net-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!