如何将数据从 vb.net 应用程序发送到 Web 服务器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17253205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:00:23  来源:igfitidea点击:

How to send data from a vb.net app to a web server?

phpmysqlvb.netweb

提问by user2502784

The app I've created in visual studio gets its data from the users pc currently stores it in a text file uploads that to the server and this is how I get the data. I was wondering if there is a way to have it send that same data without using text files but some kind of TCP connection maybe straight into a mysql server using php? How would this be done?

我在 Visual Studio 中创建的应用程序从用户 pc 获取其数据,当前将其存储在一个文本文件中,然后将其上传到服务器,这就是我获取数据的方式。我想知道是否有办法让它在不使用文本文件的情况下发送相同的数据,但某种 TCP 连接可能直接使用 php 发送到 mysql 服务器?这将如何完成?

回答by Pragmateek

You can write a simple PHP web-service, "uploaddata.php":

您可以编写一个简单的PHP 网络服务,“uploaddata.php”:

<?php
    if (isset($_POST["data"]))
    {
        echo("Saved these data: " . $_POST["data"]);
    }
    else
    {
        echo "ERROR: No data!";
    }
?>

And use it from your VB.Netusing the WebClient:

并用它从你的VB.Net使用Web客户端

Dim wc As New WebClient
wc.Headers("content-type") = "application/x-www-form-urlencoded"
Dim response As String = wc.UploadString("http://localhost/uploaddata.php", "data=123" & Environment.NewLine & "456" & Environment.NewLine & "789")
MessageBox.Show(response)

Result:

结果:

Saved these data: 123
456
789

回答by Kennyomar

Looking for a solution to a similar issue, I found Pragmateek's suggestion good. However, I used a variable WebBrowser and called the function Navigate passing as parameter the URL with the data I wanted to update on my database (hosted on a web server).

寻找类似问题的解决方案,我发现 Pragmateek 的建议很好。但是,我使用了一个变量 WebBrowser 并调用了函数 Navigate,将 URL 作为参数传递给我想要在我的数据库(托管在 Web 服务器上)上更新的数据。

This is what I mean

这就是我的意思

Dim br As New WebBrowser
br.Navigate("http://yourwebsite/your-php-script.php?your_variable=" + the_data_you_want_to_send)

This is working well so far for me.. good luck!

到目前为止,这对我来说效果很好......祝你好运!