VB.NET中的UploadString(Post方法)不起作用

时间:2009-05-08 10:13:43

标签: vb.net post webclient uploadstring

我正在尝试将简单数据发布到某个站点,在本例中是我本地服务器上的php文件。我的VB.NET代码:

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)

这里是p.php:

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

所以,当我启动VB.NET应用程序时,它只是简单地调用p.php(GET),但POST不起作用。尝试了一切。将p.php改为其他服务器,检查php中的其他变量($ _REQUEST),使用UploadString(URL,“POST”,“bla = test),使用PERL,ASP ..没有。

我正在使用.NET Framework 3.5 任何想法如何使用vb.net发布数据?

1 个答案:

答案 0 :(得分:6)

我自己想通了:

    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)