I am currently working on a c#/php project where I need to retrieve some data from the database in c# and the data to an array and send the array to php.
While I am looping through the database I am adding string values into a string list array and once it has finished I then call:
string[] myData = myList.toArray();
I am then trying to post myData to php by using the following code
Dictionary<string, string> report = new Dictionary<string, string>();
report.add("data", myData.toString());
WebRequest request = WebRequest.Create(domain + appRoot + "/administrator/engine/email-alarms.php");
request.Method = "POST";
StringBuilder b = new StringBuilder();
foreach (KeyValuePair<string, string> data in report)
{
b.Append(HttpUtility.UrlEncode(data.Key)).Append("=").Append(HttpUtility.UrlEncode(data.Value ?? "")).Append("&");
}
string postData = b.ToString(0, b.Length - 1);
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.writeLine(response);
I realise saying myData.toString() isn't the correct thing to do as it just prints System.String[] but if I don't do this then I get an error in the c# code saying that there is an invalid argument.
How can I do post the array to php?
Thanks for any help you can provide.