我有这个 php 文件:
<?php
if (isset($_POST['message']))
{
$msg = $_POST['message'];
if($msg == "age")
echo "I am 18";
else if($msg == "name")
echo "my name is Jonathan";
else
echo "I do not know";
}
?>
我想在 VB.NET 中创建一个 HttpWebRequest,这样如果我从 TextBox 发送值“age”:
要获得以下 msgbox:
我尝试了类似这样的操作:
Public Sub SendPostData(ByVal site As String, ByVal message As String)
Dim request As WebRequest
request = WebRequest.Create(site)
Dim response As WebResponse
Dim postData As String = "message=" + message
Dim data As Byte() = Encoding.UTF8.GetBytes(postData)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = data.Length
Dim stream As Stream = request.GetRequestStream()
stream.Write(data, 0, data.Length)
stream.Close()
response = request.GetResponse()
Dim sr As New StreamReader(response.GetResponseStream())
MsgBox(sr.ReadToEnd)
End Sub
我得到了这个:
知道为什么我得到它而不是 php 文件中的 3 条可能消息之一吗?(“我 18 岁”、“我叫乔纳森”或“我不知道”)?请注意,我通常从 html 表单测试 php 并且它工作,所以我想知道为什么它不能从程序工作。