I am interested in sending some data from my C# code to a php page, I can already send a single variable and even two, but when it comes to a 2D array i'm already clueless.
My goal is to send the 4 2D arrays within the arguments to a php page via the string postData
and echo back the data into one really long string (I can handle the rest when I'm able to do this) I need to send the 2D arrays so i can process them in the php file,
Here is my code: (This is the only method i know for HTTP communication)
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 " ";
}
Thank you and have a nice day =)