Click here to Skip to main content
12,951,823 members (64,792 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I want to create a desktop application ( to submit a login.php form and read the response if the login sucess or not

        <form action="checklogin.php" method="POST">
            <input type="text" name="name" size="20"><br/>
            <input type="password" name="password" size="20"><br/>
   <input type="submit" name="submit">


In c# i have created a form having two text fields for name and password

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace loginphp
    public partial class Form1 : Form
        public Form1()
        private String readHtmlPage(string url)
            //setup some variables
            String username = "rk";
            String password = "rk";
            //String firstname = "John";
            //String lastname = "Smith";
            //setup some variables end
            String result = "";
            String strPost = "name=" + username + "&password=" + password ; //+"&firstname=" + firstname + "&lastname=" + lastname;
            StreamWriter myWriter = null;
            HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
            objRequest.Method = "POST";
            objRequest.ContentLength = strPost.Length;
            objRequest.ContentType = "application/x-www-form-urlencoded";
                myWriter = new StreamWriter(objRequest.GetRequestStream());
            catch (Exception e)
                return e.Message;
            HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
            using (StreamReader sr =
               new StreamReader(objResponse.GetResponseStream()))
                result = sr.ReadToEnd();
                // Close and clean up the StreamReader
            return result;
        private void button1_Click(object sender, EventArgs e)
            label3.Text= readHtmlPage("http://localhost/spotkeys/login.html");

but it only returns the following

<form action="checklogin.php" method="POST">
<input type="text" name="name" size="20">

<input type="password" name="password" size="20">

<input type="submit" name="submit">

how can i sumbit a php form using c# and read the response if login sucess or not
Posted 11-Sep-12 19:58pm
Arun (Multithreaded) 12-Sep-12 2:08am
Your code is completely wrong.
Arun (Multithreaded) 12-Sep-12 2:10am
It does't mean...objRequest.ContentLength = strPost.Length;

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 12 Sep 2012
Copyright © CodeProject, 1999-2017
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