Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从c windows应用程序向PHP服务器发送包含对象数组的POST请求?_C#_Mysql_Http Post - Fatal编程技术网

C# 如何从c windows应用程序向PHP服务器发送包含对象数组的POST请求?

C# 如何从c windows应用程序向PHP服务器发送包含对象数组的POST请求?,c#,mysql,http-post,C#,Mysql,Http Post,我正在开发一个C应用程序,它读取本地MySQL数据库,并将数据作为POST请求发送到在线PHP服务器 PHP服务器已经准备好接收这样的数据。它来自邮递员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*

我正在开发一个C应用程序,它读取本地MySQL数据库,并将数据作为POST请求发送到在线PHP服务器

PHP服务器已经准备好接收这样的数据。它来自邮递员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
这是我的c代码。我无法将对象数组添加到字典中,所以我正在寻找其他方法

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();

除了字典,还有其他方法发送POST请求表单数据吗?

我的答案可能不是您想要的,但如果您传递字符串,您可以用c将它们连接起来;分离器和不爆管柱;关于php和get数组。还可以尝试:dictionary.Additems[],dataTable

我的答案可能不是你想要的,但如果你传递字符串,你可以用c将它们连接起来;分离器和不爆管柱;关于php和get数组。还可以尝试:dictionary.Additems[],dataTable

这个答案是否有帮助@riggsfully我认为这个答案与我的问题无关,我需要发布对象数组,同时OP那里使用字符串数组。这个答案是否有帮助@riggsfully我认为这个答案与我的问题无关,我需要发布对象数组,同时OP那里使用字符串数组。