C# コードから php ページにデータを送信することに興味があります。既に 1 つの変数、さらには 2 つの変数を送信できますが、2D 配列になると、私はすでに無知です。
私の目標は、引数内の 4 つの 2D 配列を 経由で php ページに送信しstring postData、データを 1 つの非常に長い文字列にエコー バックすることです (これができれば残りを処理できます)。2D 配列を送信する必要があります。 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 " ";
}
ありがとう、良い一日を =)