I am running a server with a mysql database on it. I am now making a C# program which has to put some data into the database. For security reasons I would send the data to a php script which inserts the data in the local mysql database.
I am trying the code below, but when I use fiddler to check if the url is called, it doesn't show up, so it seems as if the url is never called.
My code looks like this:
string result = string.Empty;
string data2 = string.Empty;
string[] postdata = new string[8];
postdata[0] = "Date";
postdata[1] = log.EndTime.ToString();
postdata[2] = "Name";
postdata[3] = log.OwnerTask.Schedule.Name;
postdata[4] = "Status";
postdata[5] = log.ParsedStatus;
postdata[6] = "Message";
postdata[7] = log.ParsedMessage;
string Url = "http://x.x.x.x/send.php";
System.Text.ASCIIEncoding ascii = new ASCIIEncoding();
for (int i = 0; i < postdata.Length; i += 2)
{
data2 += string.Format("&{0}={1}", postdata[i], postdata[i + 1]);
}
data2 = data2.Remove(0, 1);
byte[] bytesarr = ascii.GetBytes(data2);
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = bytesarr.Length;
System.IO.Stream streamwriter = request.GetRequestStream();
streamwriter.Write(bytesarr, 0, bytesarr.Length);
streamwriter.Close();
}
Can somebody help me out? Point me in the right direction?
Thanks
For security reasons I would send the data to a php script which inserts the data in the local mysql database.- Seems like the worst possible approach from a security standpoint. PHP stuff can be viewed by anyone with a browser just by pressing "view source". Create a proper Web Service instead.