Get HTTP headers on WebKit.NET - c#

I've been trying to figure out how to handle 401 responses on WebKit.NET and show an authentication box so that user can enter his credentials and then send them back to the server.
This guy figured a way to add the proper headers to a new request and send them to the server, but seems like the code is sending them to every page that the browser navigates to which is not what I want. I dug a bit into the code and there is this interface called IWebResourceLoadDelegate which among other contains two event handlers called didReceiveResponse and didReceiveContentLength that will be called for every response, but can't figure out how in the world to read the headers from the parameters being passed. I think the header is just not being passed at all.
Also, seems like the guys at web kit sharp haven't solve this issue either, but somehow Chrome does handles it properly. I'm not sure which build of WebKit Chrome uses. I just hope is not a custom build such that I won't have a choice other than spending the rest of my life trying to build WebKit (and the other rest trying to add the missing functionality).
Any one has any idea how could I begin to figure out how to handle this?

I haven't worked on this project in some time, but it looks to me like you should be able to get the request headers from the WebURLResponse object, perhaps from the allHeaderFields or statusCode methods...
It would be really great if you could finish my work to get full HTTP Auth support in WebKit.NET. I just haven't had the time... Chrome and Safari have their own proprietary implementations that do the trick.

Related

Firing hCaptcha callback function for bypass token

I'm trying to bypass the hCaptcha in Discord Account Registration using selenium webDriver in C#. I'm using CapMonster Cloud API for solving the captcha itself and as response I'm getting bypass token.
The problem that I currently have is that I can't locate the callback function that I need to call/submit, in order to pass the hCaptcha.
I'm setting the bypass token into "g-recaptcha-response" and "h-captcha-response" textareas, but can't find a way to locate and call the callback function. There is no form to be submitted.
using selenium webDriver in C#
10/10 Would recommend doing discord captcha bypasses using:
PuppeteerExtraSharp/ExtraStealth
(as selenium has some obvious tracers)
Puppeteer has a lot more freedom in it's API as well as the fact that 2capthca is a much more popular method for solving h-captchas
I know this doesn't answer your question but i hope you look into this as a potential better alternative if you do not receive a more traditional answer.
You can do that with Anti-Captcha.com plugin which will do the job automatically. It injects its own callbacks, so when a token is ready it submits the form. If you ever have problems with plugin, support guys here will help you out.
Web communication has to happen in one of the methods defined on this page
So if anything is being sent and received from a server to the browser it has to be one among those methods. Generally the most common methods are POST and GET.
The statement "There is no form to be submitted" is somewhat confusing. A form is just display of fields to collect data from a user. In case a website does not need user input they do not show the form. They would instead capture the required data and send a POST request to the server (without the user ever noticing), in a manner similar to how a form would have sent the data. This is a normal behavior for almost all major websites. An example is google-analytics codes.
So what you need to look for is a POST request (mostly or PUT maybe GET - depends) where the data you are targeting is received or sent.
In your case there indeed is a form which displays the captcha (that is how you see it) and and associated POST request which does what you need.
Url for the post request on the captcha is POST /getcaptcha?s=xxxxxxxx-xxxe-xxxx-xxxx-xxxxxxxxxxxx HTTP/3
Url where it is sent is POST /api/v9/auth/register HTTP/3
These basics apply to any web communication and not just the website in question.

Post/Get requests using HttpClient implementation

I'm trying to make a bot for a browser game, i'm really passionate about this project and i have thought about the model and everything but when i wanted to actually implement it i got lost, i know it's all about post/get requests and i watched the HTTP headers using firefox plugin and i kinda get the idea of how things works when i make an action in the game.
my question is, how can i make an HTTP post request with given info ( username + password to star with ) , that logs me into the game, and then get info ( resources for instance ) of the first page maybe?
if i can just get past that point i'll progress, i'm really stuck.
thanks.
I advise you to use fiddler(http://www.telerik.com/fiddler) to capture all the requests and then you could try to do the same using HttpClient or even HttpRequest.
Your bot should be able to make the same requests to the server as your browser do.

c# WebRequest not returning the required page, possibly a header issue

I'm writing an app to ensure my website is always up to date with our suppliers products. I can get the categories but not the subs.
Basically a webrequest on "xxxx/products/8-propagation/?sub-category=96" always returns "xxxx/products/8-propagation/". I have used console on firefox to see what headers are sent when browsing, I didn't see anything particular but still emulated.
Is there any way to retrieve php requests from URL's or is this something server side only?
I have tried numerous ways of doing this, all the same result.
Show us your server side code. I think, this is problem with your routing in controller.

Both WebClient and HttpWebRequest suddenly failing to pull basic Amazon pages?

We have an in-house application that pulls some data from some of Amazon's pages occassionally (We know they have APIs for certain operations... what we're doing requires some custom info not included in the APIs). We have never had a problem pulling their pages, but suddenly Amazon is returning "(503) Server Unavailable" on pretty much every request, and this has been happening for several days, so we doubt it's a temporary thing. Even something as simple as this:
System.Net.WebClient client = new System.Net.WebClient();
string data = client.DownloadString(new Uri("http://www.amazon.com/Bose-Companion-multimedia-speaker-Graphite/dp/B000HZBR64/"));
The strange thing is that these pages load just fine in a web browser, but any time we try to pull them through code, it is failing.
What could cause these functions to fail? Is it possible that they changed something on their end and that we need to do some custom logic with our calls?
After some further testing, it turns out that this was happening because Amazon needs the Accept parameter of the HttpWebRequest to be specifically set. When setting it to:
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
Everything worked fine. This is a recent change, so they must have altered something on their end.
check the user-agent of you request. make the user-agent the same as your browser. And check if you set any proxy for your app? maybe your browser and your app are using different proxies

Getting data from a webpage

I have an idea for an App that would really help me out in work but I'm not sure if it's possible.
I want to run a C# desktop application that will ask for a value. When a value is supplied, the application will open a browswer, go to a webpage and add the value into a form on an online website. The form is then submitted and a new page is loaded that contains a table of results. I then want to extract the table of results from the page source and write code to parse the result values.
It is not important that the user see's this happen in an actual browser. In other words if there's a way to do it by reading HTTP requests then thats great.
The biggest problem I have is getting the values into the form and then retrieving the page source after the form is submitted and the next page loads.
Any help really appreciated.
Thanks
Provided that you're only using this in a legal context:
Usually, web forms are sent via POST request to the web server, specifically some script that handles it. You can look at the HTML code for the form's page and find out the destination for the form (form's action).
You can then use a HttpWebRequest in C# to "pretend you are the form", sending a POST request with all the required parameters (adding them to the HTTP header).
As a result you will get the source code of the destination page as it would be sent to the browser. You can parse this.
This is definitely possible and you don't need to use an actual web browser for this. You can simply use a System.Net.WebClient to send your HTTP request and get an HTTP response.
I suggest to use wireshark (or you can use Firefox + Firebug) it allows you to see HTTP requests and responses. By looking at the HTTP traffic you can see exactly how you should pass your HTTP request and which parameters you should be setting.
You don't need to involve the browser with this. WebClient should do all that you require. You'll need to see what's actually being posted when you submit the form with the browser, and then you should be able to make a POST request using the WebClient and retrieve the resulting page as a string.
The docs for the WebClient constructor have a nice example.
See e.g. this question for some pointers on at least the data retrieval side. You're going to know a lot more about the http protocol before you're done with this...
Why would you do this through web pages if you don't even want the user to do anything?
Web pages are purely for interaction with users, if you simply want data transfer, use WCF.
#Brian using Wireshark will result in a very angry network manager, make sure you are actually allowed to use it.

Categories

Resources