0

How can i pass values like email, phone, name etc... to any website from my console application. I want to develop a console application which open a website URL and fill the form and submit it.

using System;
using System.Diagnostics;
using System.Net;

namespace SampleNamespace
{
    public class SampleClass
    {
        public static void Main()
                {
            string url;
            string browser="";
            string browserpath="";  
            Console.WriteLine("Please enter a website URL (eg. http://www.google.com): ");
            url=Console.ReadLine();
            while(browser.ToUpper()!="CHROME" && browser.ToUpper()!="MOZILLA" && browser.ToUpper()!="IE" && browser.ToUpper()!="OPERA")
            {
                Console.WriteLine("In which browser you want to open a website? (Chrome | Mozilla | IE | Opera) ");
                browser=Console.ReadLine();
                if (browser.ToUpper()!="CHROME" && browser.ToUpper()!="MOZILLA" && browser.ToUpper()!="IE" && browser.ToUpper()!="OPERA"){
                Console.WriteLine("Please enter correct option!!!");
            }

            if (browser.ToUpper()=="CHROME")
            {
                browserpath=@"C:\Users\weblink\AppData\Local\Google\Chrome\Application\chrome.exe";
            }
            else if(browser.ToUpper()=="MOZILLA")
            {
                browserpath=@"C:\Program Files\Mozilla Firefox\firefox.exe";
            }
            else if(browser.ToUpper()=="IE")
            {
                browserpath=@"C:\Program Files\Internet Explorer\iexplore.exe";
            }
            else if(browser.ToUpper()=="OPERA")
            {
                browserpath=@"C:\Program Files\Opera\opera.exe";
            }
            Process.Start(browserpath,url);
            System.Console.WriteLine("Please press eenter key to exit!");
            Console.ReadLine();
        }
        }
}
Ashish Sharma
  • 131
  • 1
  • 5
  • 19

1 Answers1

1

If your goal is to simply to POST to a website from your application you don't need to worry about using a browser.

You can connect directly to the website in question using a java library (eg: http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpClient.html)

There are plenty of examples of sending HTTP POST requests around:

You don't even need to load the form in question (usually). You can simply supply a POST request to the form's action (destination).

Suppose the form in question was came from http://example.com/forms/

You would POST to the URL http://example.com/forms/contact.html

If you're trying to develop a spam bot, you're way behind the curve ;-)

Community
  • 1
  • 1
Amir T
  • 2,708
  • 18
  • 21