【问题标题】:UploadString (Post Method) in VB.NET doesn't workVB.NET 中的 UploadString(发布方法)不起作用
【发布时间】:2009-05-08 10:13:43
【问题描述】:

我正在尝试将简单数据发布到某个站点,在本示例中是我本地服务器上的一个 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 发布数据?

【问题讨论】:

    标签: vb.net post webclient uploadstring


    【解决方案1】:

    我自己想通了:

        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)
    

    【讨论】:

      猜你喜欢
      • 2013-03-23
      • 1970-01-01
      • 1970-01-01
      • 2013-12-19
      • 2015-08-21
      • 2017-03-01
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      相关资源
      最近更新 更多