Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# blog command
Hi
I'm sending values ​​to the form at this link

Posted 12-Jan-13 1:22am
sara-90429

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

If you are trying to post data from a C# application to PHP form..
 
WebRequest and WebResponse Might Help you..
 
Try this..
 
C# Code:
...
using System.Net;
using System.IO;
 
...
 

 
private void SubmitData()
        {
            //This is kind of a Login Script..
            try
            {
                string user = textBox1.Text;
                string pass = textBox2.Text;
 
                ASCIIEncoding encoding = new ASCIIEncoding();
                string postData = "user=" + user + "&pass=" + pass;
                //In the above line the Name and value is set
                byte[] data = encoding.GetBytes(postData);
 
                WebRequest request = WebRequest.Create("http://codeproject.com/login.php");//This is the webpage
                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();
 
                WebResponse response = request.GetResponse();
                stream = response.GetResponseStream();
 
                StreamReader sr = new StreamReader(stream);
                string Result = sr.ReadToEnd();
                if(Result == "true")
                {
                     MessageBox.Show("The Login was Successful.");
                }
                else
                {
                     MessageBox.Show("The Login was NOT Successful.");
                }
                sr.Close();
                stream.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : " + ex.Message);
            }
        }
 

PHP Code:
 
<?php
 
if(isset($_POST['user']) && isset($_POST['pass']))
{
    $user = $_POST['user'];
    $pass = $_POST['pass'];
    if($pass == md5($user))
    echo "true";
    else
    echo "false";
}
 
?>
 

This is a small Login Script which the C# app connects to the form which is written in PHP...
 
Hope it Might Help..
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 299
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 230
3 Aajmot Sk 191
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 12 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100