I have a C# Program that currently submits information via HTTP Post.
the hosting provider I have currently does not have open access to
MySQL for this data. The client side of this solution will have to
interact with the MySQL database via PHP.
What I want to happen is the PHP script accept the following example
via post (sometimes thousand of records), and place them into a file
on a temporary directory on the server, then import this data into a
table via "LOAD DATA INFILE" (or something as fast).
[EXAMPLE SUBMIT]
Feral Potence (Master I)|1315797137|-975426244
rough lumbered rosewood|-1964321350|-826406279
Dashing Swathe (Master I)|1630518533|-1348442199
an aviak feather|72996731|-591426677
Vitae Immortalis|-83736841|-1505454180
Plumptucket's Diamond Engagement Ring|-491293255|-1750982943
a pristine large ash dining table|-1790790629|-212951619
[/EXAMPLE SUBMIT]
Heres the C# code that I currently use to connect to a webserver and post data.
[code]
private void SubmitButton_Click(object sender, EventArgs e)
{
SubmitButton.Enabled = false; // Disables a button
this.Cursor = Cursors.WaitCursor; // Changes cursor state
lblStatus.Text = "Uploading..."; // Changes the status of
the program to say uploading
lblStatus.Update(); // forces the staus change to show
string httpResult =
HttpPost("http://hroch486.icpf.cas.cz/cgi-bin/echo.pl",
uploadTextBox1.Text); // magic line that actually posts to the
website.
uploadTextBox1.Text = String.Format(httpResult); //
updates the window to show the update results
uploadTextBox1.Show(); // unhides the window
this.Cursor = Cursors.Default; // sets the cursor to default.
System.Media.SystemSounds.Beep.Play();
}
private string HttpPost(string URI, string Parameters)
{
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
//req.Proxy = new System.Net.WebProxy(ProxySettings);
// Need to put proxy settings gathered from ie or the UI there..
// decided to skip it.. most dont use it.. and ill figure
it out later ;-)
progressBar1.Value = 20; // sets the progress bar value
req.ContentType = "multipart/form-data";
req.Method = "POST";
req.Timeout = 100000;
progressBar1.Value = 40;
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = bytes.Length;
progressBar1.Value = 60;
try
{
System.IO.Stream os = req.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
os.Close();
}
catch
{
progressBar1.Value = 100;
return "Server is Unreachable Please check the
settings and try again";
}
progressBar1.Value = 80;
System.Net.WebResponse resp = req.GetResponse();
if (resp == null) return null;
System.IO.StreamReader sr = new
System.IO.StreamReader(resp.GetResponseStream());
progressBar1.Value = 100;
return sr.ReadToEnd().Trim();
}
[/code] |