How do you programmatically fill in a form and 'POST' a web page?
The code will look something like this:
WebRequest req = WebRequest.Create("http://mysite/myform.aspx");
string postData = "item1=11111&item2=22222&Item3=33333";
byte[] send = Encoding.Default.GetBytes(postData);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = send.Length;
Stream sout = req.GetRequestStream();
sout.Write(send, 0, send.Length);
sout.Flush();
sout.Close();
WebResponse res = req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
string returnvalue = sr.ReadToEnd();
c# - programmatically form fill and submit login
yes some sites block request. but you can check the login with auth cookie. Use HttpWebRequest/HttpWebResponse
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url));
byte[] data = Encoding.Default.GetBytes("item1=11111&item2=22222&Item3=33333");
request.Method = "POST";
request.ContentLength = data.Length;
Stream sout = request.GetRequestStream();
sout.Write(data, 0, data.Length);
sout.Flush();
sout.Close();
request.CookieContainer = new CookieContainer();
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
now check response.Cookies
for auth cookie
Filling out a web form automatically with a text file
You can write a json object, then a javascript function that iterate that json and figure out by each value the selector of the correct input to use and set the correct value.
Then when the page open, use the dev console.
paste the json object, paste the function.
Run the function and the form should get fill out.
=)
Fill in web form from an app and submit
I have used something like this in the past. However you will have to load a webview (though you dont need to show it.) then do something like below. Keep in mind that if the site changes the id down the road this approach will not work.
webView.loadUrl("javascript:var
name=document.getElementById('nameInput').value='" yourNameValue "'");
webView.loadUrl("javascript:document.getElementById('submit').click()");
write a code to fill a form on the web and read one of the elements
Yes we can.. one way to do it using VBS is here:
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = 1
objIE.navigate "<login url>"
WScript.Echo "Opening login page..."
WScript.Sleep 100
Do while objIE.busy
Wscript.sleep 200
Loop
WScript.Echo "Setting credentials..."
objIE.Document.getElementByID("ap_email").Value = user 'id of the input element
objIE.Document.getElementByID("ap_password").Value = pass
WScript.Echo "Email and password set!"
Call objIE.Document.Forms(0).submit
HTH!
Related Topics
Is There a Jquery-Like CSS/HTML Selector That Can Be Used in C#
Adding Stylesheets Programmatically in ASP.NET
Calling Unix and Linux Shared Object File .So from C#
Ide's for C# Development on Linux
Bundler Not Including .Min Files
Accessing MVC's Model Property from JavaScript
How to Post an Array of Complex Objects with JSON, Jquery to ASP.NET MVC Controller
Running Scripts in HTMLagilitypack
How Does the Ternary Operator Work
What Is the Equivalent of the Java Bigdecimal Class in C#
Automatically Set Appsettings.JSON for Dev and Release Environments in ASP.NET Core
Turn a Simple C# Dll into a Com Interop Component
Conversion of System.Array to List
Cancellation Token in Task Constructor: Why
Evaluate String with Math Operators
Reference Assignment Is Atomic So Why Is Interlocked.Exchange(Ref Object, Object) Needed