[英]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.