I'm developing a C# application that reads local MySQL database, and send the data as POST request to online PHP server.
The PHP server is ready to receive data like this. (It is from Postman x-www-form-url-encoded)
token:da979d2922c74d7851e6f0eff2270d73
branch:JKT
items[0][code]:0001-W*XL*B
items[0][name]:018/17 DRS XL BLUE
items[0][stock]:0
items[1][code]:0001-W*XL*BK
items[1][name]:018/17 DRS XL BLACK
items[1][stock]:0
This is my c# code. I can't add array of objects to dictionary, so I'm looking for other way around.
string query = "SELECT * FROM items";
db.Connection.Open();
MySqlDataAdapter dataAdapter = new MySqlDataAdapter(query, db.Connection);
DataTable dataTable = new DataTable();
dataAdapter.Fill(dataTable);
db.Connection.Close();
var dictionary = new Dictionary<string, string>();
dictionary.Add("token", "da979d2922c74d7851e6f0eff2270d73");
dictionary.Add("branch", "JKT");
dictionary.Add("items", dataTable); // Argument 2: cannot convert from 'System.Data.DataTable' to 'string'
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://mysite.test/sync")
{
Content = new FormUrlEncodedContent(dictionary)
};
var response = await client.SendAsync(request);
string responseString = await response.Content.ReadAsStringAsync();
Is there other way to send POST request form data aside from Dictionary?