VB.NET中的UploadString(发布方法)不起作用 [英] UploadString (Post Method) in VB.NET doesn't work

查看:191
本文介绍了VB.NET中的UploadString(发布方法)不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

这里是p.php:

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

因此,当我启动VB.NET App时,它只是简单地调用了p.php(GET),但POST不起作用.尝试了一切.将p.php升级到其他服务器,检查php($ _REQUEST)中的其他变量,使用UploadString(URL,"POST","bla = test),使用PERL,ASP ..没什么.

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.

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

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

推荐答案

我自己弄清楚了:

    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)

这篇关于VB.NET中的UploadString(发布方法)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆