I've been working on this for a few days and can't seem to get it working.
I want to be able to get, and send text (numbers to be specific) to a online file where it can be stored.
At the moment I use:
WebClient wc = new WebClient();
string text = wc.DownloadString("domain.com");
MessageBox.Show(text);
But it's not great as I can't easily send data, I also want to be able to delete data when its been received a certain amount of times.
I want each item to get uploaded to the same same file, so they can be received individually, and removed one they have been received a certain amount of time.
I have full have access to a web server if needed.
How do I achieve this?
Have tried:
WebClient WC = new WebClient();
string myContent = "test";
string responseString = WC.UploadString("ftp://192.99.1??9.66/www/test.txt", myContent);
Obviously didnt have the question marks.
You should post it as a regular HTTP request, or use something like FTP to write files.
You have the built-in upload methods that do the appropriate HTTP post or FTP requests in the WebClient
class already:
byte[] responseArray = wc.UploadFile("ftp://domain/thefile.txt" , @"C:\anyfile.txt");
byte[] responseArray = wc.UploadFile("http://domain/thefile.txt" , @"C:\anyfile.txt");
The last one needs some sort of technology that handles the HTTP POST request, like a webservice. The first one needs an active and accepting FTP server.
Or to send a string
:
string myContent = "some data here";
string responseString = wc.UploadString("ftp://domain/thefile.txt" , myContent);
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.