How Design A Software to InputData In WebForm Automatically? - c#

I Want Create A Software to Input Data in WebForms Automatically (like Robot) And Accept Input Data.
How I Can Create this Software in C# (Windows Application)?
what Technologies Must Be Used?
What OpenSource Project Exist for use?
Sample Code And etc...
Please Help Me

I hope you're doing something within the acceptable terms of use with the content you automatically post. Ie. you do not ask how to create yet another spam bot...
To grab the HTTP form you can use WebRequest. This returns the content of the page (including the form) as a response stream. You can then parse the response using HtmlAgility pack, for the forms you are interested. Once you know the forms and fields in the page, you can set values for the fields and post a response, again using a WebRequest but changing the method to POST and encoding the reponse fields as application/x-www-form-urlencoded content, see How to: Send Data Using the WebRequest Class.
This method is using almost the most basic building blocks, going lower level than this would mean using sockets and formating the HTTP request yourself. At this low level you'll have a great deal of freedom and flexibility on how to parse the form and send back the request, at the cost of actually having to understand how WebForms and HTTP work.

Related

How to make a Hello World application without HTML tags?

I'm used to PHP and I wanted to make a totally empty asp.net page "Hello World" (in the source code) I.E. not "<html><p>Hello World</p></html>" I want to totally strip it all out (and possibly manipulate the headers) so the view source is Hello World.
This is because I am writing an asp.net throughput environment (basically a triangulation server, to facilitate network security) that effectively redirects so I want to have no outputs that I don't accurately control.
Incidentally this also includes response headers as well. Full Control basically.
This is what I have so far
Dynamically, the browser do create "html", "body" etc... basic tags. It's the DOM, created by the browser from what it received.
To explore what you actually received from the server, you can inspect the source. Or better, use developer tools in your browser to look at the network part (to allow you to explore headers as well).
To manipulate what you send, you have to manipulate the context.Response object.
You can add all the headers you want from there.
from more info, see for example :
https://msdn.microsoft.com/en-us/library/system.web.httpresponse(v=vs.110).aspx
To add headers, see for example this question :
How to add Headers in HTTPContext Response in ASP.NET MVC 3?
example:
HttpContext.Current.Response.AppendHeader("Content-Length", contentLength);
What you use is the DOM explorer not the source code. Right click on the page and select View source. I bet the tags aren't there.
Headers can be displayed in the network tab. Just click on the page request in the network tab and you will see details like headers.

CEF sharp 3 retriving response headers

So Im still trying to find the feature (if it is there) in Cefsharp 3, where one can inspect the headers from the response of a request. In case its not there, is it because it is not there in CEF 3 ? and or, where should i start looking, if Im to implement it ?
This feature is not in CEF 3 yet. Here's the outstanding issue for it:
https://code.google.com/p/chromiumembedded/issues/detail?id=515
There is a workaround noted...
There's no great way to filter response contents with CEF3 currently. You can use CefResourceHandler via CefRequestHandler::GetResourceHandler and execute the request/return the response contents yourself using CefURLRequest.
... however this workaround is not possible in CefSharp 3 because CefURLRequestClient and friends are not implemented.
At this stage, depending on how comfortable you are with C++ you might consider:
contributing to the (C++) CEF project and implement the response filtering feature - this will be all C++.
contributing C# wrappers of CefURLRequestClient and friends to the CefSharp project - which is a combination of light C++ and C#.
You might also be interested that there is a way to get HTTP headers in JavaScript, as long as you have initiated the request yourself using AJAX:
Accessing the web page's HTTP Headers in JavaScript
This type of solution could easily be done with CefSharp 3 by injecting JavaScript into the current page.
An alternative that provides more control is to use schemehandlers (it's cleaner IMO).
Add a scheme handler that intercepts your resource loading:
CEF.RegisterScheme("ascheme", new HandlerFactory());
then (once you've created a trivial factory or 2) you have this override available:
public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback)
The Response contains Headers/MimeType and Stream to allow more control. I hope this helps.

How to pass XML data to web page running in web browser control?

I have windows application in which web page is loaded using the windows (.NET) browser control. The windows application needs to send some information to the web page (aspx) and now it's achieved using query string.
Now we want to send more details which may be in the XML format.
How can we pass the large amount of data (like XML) in such case?
If you want to send (more) data, you should use method POST. (That way you don't really need to care whether it's XML or something as long as the particular form can handle it correctly.)
Query string should be used only to specify the resource. Typically query string is used with GET method like http://server/giveme.php?report&number=123. (If that string is used with browser, it should open connection to server:80 and say GET /giveme.php?report&number=123. (Then some headers follow, etc.)
Use of POST is very similar except that after the method, URI (/hereis.php?report&number=124) and some HTTP headers, also data is sent (which can really be any data).
Also remember that GET is supposed to be used only for queries: you can call GET /giveme.php?report&number=123 a thousand times and you should still get the same report no. 123 (or some updated version). (So GET should not be used to send data, but to get data.)
For POST, this is not expected: Each time POST from you is accepted, you actually post some data to the server, and normally you should not get away with doing POST /hereis.php?report&number=124 multiple times. (Well, you can design your application to accept POST /hereis.php?report, but that's up to you and it's another story.)

how to download a partial web page using .net

We are downloading a full web page using System.Net.WebClient class. But we only want less than half of the page. So is there a way to download a portion of the page, say 1/3rd, half etc of a page using .net library so that We can save the network bandwidth and the space? If so, please throw your ideas, thanks.
You need to provide an "Accept-Ranges header" to your GET or POST request. That can be done by using the AddRange method of your HttpWebRequest:
HttpWebRequest myHttpWebRequest =
(HttpWebRequest)WebRequest.Create("http://www.foo.com");
myHttpWebRequest.AddRange(0,100);
That would yield the first 100 bytes. The server, however, needs to support this.
The sort answer is not unless the web app supports some way to tailor it's response to what you want it to return.
This could take the form of a
query string parameter
header field value
The simplest way to add this would be a query string parameter and when detected write out the necessary HTML to the response object. If you are unable to make changes to the web app then you won't be able to control how much of a page is returned to you.
You might want to read up on how HTTP works since the question and it's answer relies upon this. Specifically the Header Definition should be helpful.

Guitar Tab API?

I was just curious if anyone has heard of any sort of API for guitar tabs? The thought passed through my mind that it would be really neat if I could grab guitar tabs from the internet to bring into my C# app, but haven't been able to find anything.
Thanks,
Chris
You can use System.Net.WebRequest to read the repository of your choice.
You can also use System.ServiceModel.Syndication.SyndicationFeed to read RSS feeds.
EDIT: Try scraping http://www.mxtabs.net/guitar_tabs/ using WebRequest.
You can write code that sends requests to the pages of that (or any other) website and parses the responses to extract information.
However, you might want to get their permission first. They might even offer you an API.
You should approach it from another angle.. Why isn't there a good data format to transfer guitar tab data? I mean, ASCII art is good but it is easily damaged, and it doesn't convery timing information well.
If you could come up with a format that could reach critical mass, that would be a good thing.
To scrape a web page, first figure out exactly which data you want to extract.
Visit the relevant pages with Fiddler running, and look at the HTTP requests and responses that you get.
You can then write C# code that requests the relevant page and reads through the response, line by line, looking for lines that you're interested in.
If the web page is XHTML compliant, you can also parse it using XDocument, but most web pages aren't.
http://www.911tabs.com/ seems to have a large selection, and they appear to all be a variant of ASCII-art, so it would be relatively easy to write an HTML- or text-scraping routine. They don't appear to use a very standardized format, however, so this might be more work than I think.

Categories