vb.net从php脚本接收响应

时间:2016-07-28 18:36:47

标签: php vb.net

我的应用程序(用vb.net编写)将数据发送到托管在其中一个免费虚拟主机服务器上的php脚本。 php脚本评估数据,并做出相应的响应。服务器的响应如下所示:

Valid 
<!-- Hosting3322 Analytics Code -->
<script type="text/javascript" src="theurlforthewebsite/count.php"></script>
<!-- End of Analytics Code -->

'有效'来自我的php脚本。其余的是服务器上的一个小脚本,它们隐藏在每个页面中。

这是php脚本:

<?php
$d = $_POST['mac'];
if($d=='45bgd0434')
 echo "Valid";
else 
 echo "Invalid";
?>

这是我的vb.net代码:

            ' Create a request using a URL that can receive a post. 
            Dim request As WebRequest = WebRequest.Create("http://sitename.com/verify.php")

            ' Set the Method property of the request to POST.
            request.Method = "POST"
            ' Create POST data and convert it to a byte array.
            Dim postData As String = "mac=45bgd0434"
            Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)

            ' Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded"

            ' Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length

            ' Get the request stream.
            Dim dataStream As Stream = request.GetRequestStream()

            ' Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length)

            ' Close the Stream object.
            dataStream.Close()

            ' Get the response.
            Dim response As WebResponse = request.GetResponse()


            ' Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream()

            ' Open the stream using a StreamReader for easy access.
            Dim reader As New StreamReader(dataStream)

            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()


            ' Clean up the streams.
            reader.Close()
            dataStream.Close()
            response.Close()
            MessageBox.Show(responseFromServer)

我只想要输出而不是额外的代码。有什么方法可以使用替代方法在PHP中打印,或者可能是我可以与服务器通信的另一种方法? 我在互联网上尝试过其他免费服务器,但它们似乎都放入了一些代码。真的很感谢你的帮助。

0 个答案:

没有答案