我有兴趣将一些数据从我的 C# 代码发送到一个 php 页面,我已经可以发送一个变量甚至两个,但是当涉及到一个二维数组时,我已经一无所知了。
string postData
我的目标是将参数中的 4 个二维数组通过所以我可以在 php 文件中处理它们,
这是我的代码:(这是我知道的用于 HTTP 通信的唯一方法)
private String communicateToServer(String serverHostname, String[,] disk = null,
String[,] hdd = null, String[,] nic = null, String[,] ram = null)
{
try
{
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "user=" + SystemInformation.ComputerName; // user = a string containing the hostname
byte[] data = encoding.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serverHostname); // its a link to a page
request.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIPEndPointCallback);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
String returnValue = sr.ReadToEnd();
sr.Close();
stream.Close();
return returnValue;
}
catch (Exception ex)
{
MessageBox.Show("Error : " + ex.Message);
}
return " ";
}
谢谢你,祝你有美好的一天=)