我正在 php 服务器上上传带有 C# 代码的文件。但面临一些问题。
首先,我使用 WebClient 对象通过调用 UploadFile() 方法上传文件,并通过以下代码调用 UploadString() 方法上传字符串:
String StoreID = "First Store";
WebClient Client = new WebClient();
String s = Client.UploadString("http://localhost/upload.php", "POST", StoreID);
Client.Headers.Add("Content-Type","binary/octet-stream");
byte[] result = Client.UploadFile("http://localhost/upload.php", "POST", "C:\\aaaa.jpg");
s = s + System.Text.Encoding.UTF8.GetString(result,0,result.Length);
问题是我请求了两次,所以字符串和文件没有同时发送。我收到字符串或文件。但我同时需要两者。我不想使用UploadData()因为它会使用字节码,而且我知道我知道如何在 php 中提取它。
Let that string is folder name, i have to send string and file, so that file could save at specified folder at php server.
I studied there may be a solution with WebRequest and WebResponse object. But dont know how to send request using WebResponse by C# and get it at PHP.
Any Suggestions!!!!