C# File POST Request for PHP Script
-
There's a program that occasionally creates a file log (log.txt) that should be sent to the php for preservation. There's a working option for html. We only need the same on C#.
Code html:
<form action="http://site.ru/in.php" method="post" enctype="multipart/form-data">
Code php:
<?php if(is_uploaded_file($_FILES["pass_file"]["tmp_name"])){ move_uploaded_file($_FILES["pass_file"]["tmp_name"], "files/".$_FILES["pass_file"]["name"]); echo "OK";} else { echo("ERROR");?>
My knowledge C# ends with this:
C#
WebRequest send = WebRequest.Create("http://site.ru/in.php"); send.Method = "POST"; send.ContentType = "multipart/form-data";
I tried that:
WebClient wc = new WebClient(); var send = wc.UploadFile("http://site.ru/in.php", "POST", @"C:\Programm\log.txt");
-
using (var client = new System.Net.WebClient()) { client.UploadFile("http://site/upload.php", @"c:\some\file.txt"); }