简体   繁体   中英

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

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?

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

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

And use it from your VB.Net using the WebClient :

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

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).

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM