简体   繁体   English

如何将表单值(例如电子邮件,姓名,电话等)从C#控制台应用程序传递到任何网站?

[英]How can I pass form values like email, name, phone etc from my C# console application to any website?

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. 我想开发一个控制台应用程序,该应用程序打开网站URL并填写表格并提交。

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();
        }
        }
}

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 ) 您可以使用Java库直接连接到相关网站(例如: 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: 有很多发送HTTP POST请求的示例:

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). 您只需向表单的操作(目标)提供POST请求即可。

Suppose the form in question was came from http://example.com/forms/ 假设有问题的表单来自http://example.com/forms/

You would POST to the URL http://example.com/forms/contact.html 您将发布到URL http://example.com/forms/contact.html

If you're trying to develop a spam bot, you're way behind the curve ;-) 如果您想开发一个垃圾邮件机器人,那您就落伍了;-)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用MVC 5 C#将表单中的值传递到电子邮件正文中 - How do I pass the values from my form into an email body using MVC 5 C# C#:我想像文件路径一样将消息传递给我的表单应用程序,比如控制台应用程序,我该怎么做? - C#: I want to pass messages like a file path to my forms application like a console application, how would I do that? 如何将C#表单中的值传递给Python - How can i pass values from a C# form into Python 如何将ID中的值(例如Active Directory中的名称等)传递到列表,并将其保存在另一个列表(C#)中? - How to pass values from ID (like name etc. from Active Directory) to list, and save it in another list (C#)? 如何将控制台应用程序中的变量值传递给 C# 中的 windows 表单应用程序(Visual Studio) - How do i pass a variable value from Console application to windows form application in C# (visual studio) 如何将列表从我的第一个表单传递到第二个表单,向其中添加数据,然后在我的第一个表单上显示它? C# - How can i pass a list from my first form to a second form, add data to it and then show it on my first form? C# 我如何将我的imageButton值传递给C#函数 - How can i pass my imagebutton values to c# function 如何在C#中同时将datagridview的多个单元格值从一种形式传递到另一种形式? - How can I pass multiple cell values of datagridview from one form to another at same time in C#? 我可以在我的C#GUI应用程序中构建控制台应用程序吗? - Can I build a console application into my C# GUI application? 如何在C#中将值从Entity传递到Presentation - How can I pass values from Entity to Presentation in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM