I have a device with a built-in WebGUI that is accessible through it's IP address. I am trying to be able to programmatically manipulate inputs to the device with a console app. The device's login page (https://192.168.x.x/login.html) contains the following form:
<form class="settingNameTxt" method="post" action="back.shtml">
<table>
<tr>
<td>Password:</td>
<td><input type="password" size="8" maxlength="8" name="Password"></td>
</tr>
</table>
<br/>
<input type="submit" value="Submit"/>
<input type="reset"/>
/form>
I want to build a WebRequest that is the equivalent of a user viewing the page in a browser, filling in the password field, and clicking the Submit button. I've searched around here and found a few things that seem to give me the idea that it can be done, but I'm struggling to figure it out. Any ideas?
Related
Our website has following one time payment buttons.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="custom" value="#Model.UserId.ToString()">
<input type="hidden" name="notify_url" value="http://www.testweb.com/paypal/IpnHandler">
<input type="hidden" name="return" value="http://www.testweb.com/paypal/Onetimeyearlysuccess">
<input type="hidden" name="cancel_return" value="http://www.testweb.com/paypal/cancel">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="8xxxxxxC">
<input type="image" src="#Url.Content("~/images/OneTime55year.png")" border="0" name="submit" style="width: 130px !important; height: 47px !important;" alt="PayPal - The safer, easier way to pay online!" >
</form>
After done the paypal payment, we could see we are getting 404 error.
The issue is that we are getting wrong URL.
https://www.testweb.com/PaypalOnetimeyearlysuccess?amt=55.00&cc=USD&cm=22028&item_name=oneTimeAnnual55&st=Completed&tx=59M0424544743135Y
We don’t know why the slash missing after paypal.
The correct URL should be
https://www.testweb.com/Paypal/Onetimeyearlysuccess?amt=55.00&cc=USD&cm=22028&item_name=oneTimeAnnual55&st=Completed&tx=59M0424544743135Y
There needs to be slash symbol after paypal in the address URL.
You can see the correct URL from the return URL of the paypal button also.
Why it is redirecting to wrong address?
Also for testing purpose,we changed the return URL of the paypal button. We simply modified to “http://www.testweb.com/paypal/Onetimeyearlysuccesstest.”
But we could see after changed the return URL , paypal is not redirecting to modified URL.
Actually we are confused ,we need to know where the return URL is creating.
PayPal only recognize the value of 'return' variable. The key point is located at this URL (http://www.testweb.com/paypal/Onetimeyearlysuccess). You are advised to create a fixed single page without redirect function like .html, .php, .aspx, etc., to see the result.
I have a search box on my site.
The controller looks like this:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SearchResults(SearchModel model)
{
View:
<div class="siteSearch clearfix" role="search">
<form id="HeaderSearchForm">
#Html.AntiForgeryToken()
<label for="tbSiteSearch">Search:</label>
<input type="text" id="tbSiteSearch" name="tbSiteSearch" class="text" />
<button type="submit" class="btn submit">
<i class="icon-search"></i>
</button>
</form>
</div>
So when I do a search, I can see the hidden label with the Anti Forgery Token present. This all works as expected because if I take a blank html page, copy the form code and leave the '__RequestVerificationToken' blank, I get told that the token hasn't been set and the search doesn't run. Which is what I would expect.
The issue I have is if I submit a search, copy the token from my site and place it in to my blank html page e.g.
<html>
<body>
<script>history.pushState('', '', '/')</script>
<form action="https://www.adomainname.co.uk/Search/SearchResults/" method="POST">
<input type="hidden" name="SearchTerm" value="testing" />
<input type="hidden" name="__RequestVerificationToken" value="theverificationtokengoeshere" />
<input type="submit" value="Submit request" />
</form>
</body>
</html>
The request is submitted - even if I am running the above code on localhost. I would have expected the form to not submit as it was coming from a different domain. Am I misunderstanding how this should work?
If I refresh the page and resubmit Im obviously allocated a new AFT and so the submit fails again but this doesn't feel right.
Ideally I would prefer the form action to only run on the domain it's on and not be able to execute the action from another site. I thought using AntiForgeryToken prevent Cross-Site Request Forgery.
If any of this is unclear, please let me know and I'll explain more.
I have to login on page automatically using c#, for example I have on server side index.php which looks like this:
<?php
if($_POST['pass'] == "pass123")
echo "Logged";
else
echo "Failed";
?>
Form look like this:
<div align="center">
<form action="index.php" method="post">
<table width="380" style="margin-top:50px">
<tr>
<td height="40" align="center">
<fieldset><legend>Form Login</legend><br>
<input type="password" name="pass" value="" size="20">
<input type="submit" value="Login"><br><br>
</fieldset>
</td>
</tr>
</table>
</form>
</div>
And my question is how to start build c# app which should insert password in input pass, press submit and let me ktow there is Logged or Failed.
I was search it, but always is with using set "word" and click button with events, i don't want gui and download source code of page.
Regards
If you don't want a GUI and you don't want to download the pages source, the only other way I can see is to directly send a POST to the php file through the WebClient class, outlined in this Stack Overflow question.
var url = "test.php";
using (var wb = new WebClient())
{
var data = new NameValueCollection();
data["pass"] = "pass123";
var response = wb.UploadValues(url, "POST", data);
}
I have a program I have created for work that keeps track of information. We get this information from various intranet sites. I am wanting to include a form on my program that will essentially be a customized web browser that allows me to navigate those sites more easily. This is a learning project for me so please forgive my inexperience.
For this question I am looking for a way after loading a page with the browser control I can log in to that page from credentials stored in a string. I do not have access to the HTML code of the site I am trying to input this information in to and have seen many tutorials on how to do this via GetElementId but after using Firebug I found neither of the two textboxes I need to input into have an id (that I can see anyway). The site never changes and I did consider using the GetElementFromPoint but not sure how to go about it this way and it did not seem optimal. GetElementsByTagName seems to be the best way of going about it but am unsure of how to implement the code.
Here is the information of the two elements i was able to get from firebug.
Username textbox:
<input type="text" name="j_username" size="12" onblur="this.value=this.value.toLowerCase(); setUserIdCookie();" click="this.value=this.value.toLowerCase();" onkeyup="this.value=this.value.toLowerCase();">
Password textbox:
<input type="password" onkeypress="checkCapsLock( event )" name="j_password" size="12">
So i need to pass for example from my Winform usernameString to the j_username and then passwordString to the j_password and then click the <input type="submit" name="submit" value="Login">button within the web control. If i can get an idea of how to go about this from this one site I should be able to learn enough from it to implement in the other sites as well.
Thanks in advance for any assistance and please let me know if any other information is required please.
The full HTML Code:
<form method="POST"action="j_security_check" name="login">
<table border="0"width="30%"cellspacing="3"cellpadding="2">
<tr>
<td class="default"><b>Login</b></td>
<td class="default"><input onkeyup="this.value=this.value.toLowerCase();"
click="this.value=this.value.toLowerCase();"
onblur="this.value=this.value.toLowerCase(); setUserIdCookie();"
type="text"size="12" name="j_username"></td>
</tr>
<tr>
<td class="default"><b>Password</b></td>
<td class="default"><input type="password" size="12"
name="j_password"onKeyPress="checkCapsLock( event )"></td>
</tr>
<tr>
<td colspan="2" align="center"><p class="default">
<inputtype="submit"value="Login"name="submit"></td>
</tr>
</table>
</form>
EDIT
I have found a way to input in to the boxes
var x = webBrowser1.Document.All.GetElementsByName("j_username");
x[0].InnerText = (usernameString);
var y = webBrowser1.Document.All.GetElementsByName("j_password");
y[0].InnerText = (passwordString);
But am having trouble figuring out how to click the Login button
Of course after posting this nice long post and working on this for hours i finally stumbled upon the answer. For anyone who is having the same issue I was here is a way to accomplish this. In my scenario this solution works well:
private void button4_Click(object sender, EventArgs e)
{
//Set username and password strings
string usernameString = "username";
string passwordString = "password";
//Input in to username field
var x = webBrowser1.Document.All.GetElementsByName("j_username");
x[0].InnerText = (usernameString);
//Input in to password fields
var y = webBrowser1.Document.All.GetElementsByName("j_password");
y[0].InnerText = (passwordString);
//Click the login button
var s = webBrowser1.Document.All.GetElementsByName("submit");
s[0].InvokeMember("click");
}
I am working on a ASP.NET + Paypal Express project,
Website only have 1 $10 product but customer can buy it in quantities (i.e 1 or 4 or 20 etc )
Its like a paypal cart but only with 1 product with quantities.
I have searched a lot but unable to find some suitable one.
Also I want to redirect my customer to a form after paying money on paypal website.
Can you just tell me the simplest method ?
Also I have few more question :-
using minicart Paypal is suitable for this?
Do I need to configure Paypal Express account & what to configure ?
Thanks a lot :)
=================================================================
Update : Use Paypal mini cart if you need simple integration
Add cart script.js before the body tag ( https://minicart.paypal-labs.com/ )
After that All you need to add this code in your html
<div class="demo container" align="center" >
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<fieldset>
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<input type="hidden" name="business" value="#gmail.com">
<input type="hidden" name="item_name" value="Buy Our Services">
<input type="hidden" name="amount" value="6.00">
<%--<input type="hidden" name="discount_amount" value="1.00">--%>
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="return" value="https://minicart.paypal-labs.com/?success">
<input type="hidden" name="cancel_return" value="https://minicart.paypal-labs.com/?cancel">
<strong>Service</strong>
<ul>
<li>Price: $6.00</li>
</ul>
<input type="submit" name="submit" value="Add to cart" class="button">
</fieldset>
</form>
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" class="last">
<fieldset>
<input type="hidden" name="business" value="#gmail.com">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="display" value="1">
<input type="submit" name="submit" value="View your cart" class="button">
</fieldset>
</form>
</div>
Change parameter accordingly & remove link to paypal instead of sandbox
You Paypal cart is ready to go.
If you want a more flexible solution then you should check this URL http://www.codeproject.com/KB/aspnet/paypal_c_aspnet.aspx
Thanks
Panky are you sure is it the right way ?
Customer come on site
Choose product/s and quantity/ies
Before do that you should store in session/database/cookies info that you need and pass to paypal only the stuff that you need with an id or other stuff which could be used to recognized customer too.
then move to pay to paypal.
Customer pay on paypal and paypal send back info about transaction
With these details you may re-create all the info that you need ans can use to complete first step back office tasks or even you may only show some message to cusotmer.
then you will wait ipn's(Instant Payment Notification) callback in order to make all tasks needed in backoffice automation.
This is the right way to do it.
Also you may able to make a good exception handling in order to prevent issue within it.