Google Answers Logo
View Question
 
Q: Post using C# via HTTP to a MYSQL database using PHP. (Need PHP/C# help) ( No Answer,   2 Comments )
Question  
Subject: Post using C# via HTTP to a MYSQL database using PHP. (Need PHP/C# help)
Category: Computers > Programming
Asked by: jdholycross-ga
List Price: $40.00
Posted: 14 Aug 2006 16:35 PDT
Expires: 15 Aug 2006 21:42 PDT
Question ID: 756002
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]

Clarification of Question by jdholycross-ga on 14 Aug 2006 16:43 PDT
HttpPost("http://hroch486.icpf.cas.cz/cgi-bin/echo.pl", uploadTextBox1.Text); 

The website above is just a test and should not be confused with the
final destination.. which is not made yet ;-)
Answer  
There is no answer at this time.

Comments  
Subject: Re: Post using C# via HTTP to a MYSQL database using PHP. (Need PHP/C# help)
From: chrislomax-ga on 15 Aug 2006 04:13 PDT
 
I know this is not the answer you are looking for but i would just
change provider so that you can access the MySQL database direct. I
did and believe me i have never looked back!
Subject: Re: Post using C# via HTTP to a MYSQL database using PHP. (Need PHP/C# help)
From: jdholycross-ga on 15 Aug 2006 17:36 PDT
 
As this is a hobby project.. my funds are limited and i haven't found
a site that was reasonable in price. =(

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy