问题
My question resembles a lot of question but I have seen that my question is different. I wanted to apply CRUD operation on file uploading using C#(Windows Form Application). Here is the code I wanted to use...
Code:
async void uploadImage(string url, string api_key, string device_token, string device_type, string email,string file_name)
{
IEnumerable<KeyValuePair<string, string>> queries = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("email",email),
// new KeyValuePair<string, string>("files",file_name),
new KeyValuePair<string, string>("api_key",api_key),
new KeyValuePair<string, string>("device_token",device_token),
new KeyValuePair<string, string>("device_type",device_type)
};
HttpContent q = new FormUrlEncodedContent(queries);
using (HttpClient client = new HttpClient())
{
using (HttpResponseMessage response = await client.PostAsync(url, q))
{
using (HttpContent content = response.Content)
{
try
{
var mycontent = await content.ReadAsStringAsync();
var jo = JObject.Parse(mycontent);
string errorStatus = jo["Result"]["error"].ToString();
string message = jo["Result"]["message"].ToString();
if (errorStatus == "False")
{
MessageBox.Show(message);
}
else
{
MessageBox.Show(message);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
Please help me, how can I do that? Your cooperation will be highly Appreciated
来源:https://stackoverflow.com/questions/52539590/how-to-upload-some-files-of-any-type-to-online-server-by-sending-data-to-php-api