I'm using a WebBrowser control in Silverlight and I'm setting it to a local HTML page. The HTML page has various links and they all work fine. Can I make it so that if the user clicks on an image file, it downloads to their system (or does the default behavior of the broweser) instead of displaying on the webpage? The main question is, is it possible to do this if I don't have access to the server itself? Thanks
edit - Is it possible to send an HTTPWebRequest to get the image and then edit the response headers, all from the client? This may be an alternative.
The standard way of doing this is to send the Content-Disposition HTTP header with attachment as the value. See here for more on this: Uses of content-disposition in an HTTP response header
But if you don't have access to the server, I don't think you can achieve this.
Related
I want to download content of one website programatically and it looks like this content is loaded by ajax calls. When I simply disable javascript in my browser, only 1 request is made by this page and all content is loaded without AJAX.
What I need to achieve is to make a web request which will tell web page that I have disabled javascript so it returns me all the content and not just empty body tag with no content at all.
Any suggestions how to do that?
You need to mimic browser.
Steps:
Use Fiddler and see what is sent by browser.
Set the same headers/cookies/user agent via C# code.
If does not work - compare request your code makes with browser's one by using Fiddler as proxy for your C# code (set proxy to http://localhost:8888)
I have learned to use http request (create and Getresponse) methods to get the header and content of a link.
Problem is that, it is not the link that I want, that I get as http response.
There is an authentication page that comes instead. Only when I click the accept button, do I reach the page I want.
So the header and content that I actually get is of the authentication page.
Is there a way I can use this header and content to create ones more http request to get the page that I want?
I need to click the accept button in the background.
Thanks.
I'd recommend using Fiddler to capture the interaction with the site using a browser. You can then use the Fiddler output as a guide for replicating the same functionality using your code.
If the site is keeping track of whether or not each user has clicked the Accept button on a per-session basis you'll need to replicate that, probably with an HTTP POST. You'll be able to see how to construct that POST, if relevant, from the Fiddler output.
I am attempting to post a reply to an image board website.
It can be done through a winform web browser control or http request.
The issue is that with a post, you can upload an image with a input type file element on the page
<input type="file" />
For security reasons, I cannot set the value of the element to the file I want to upload.
When I use tamper data to see what is passed to the posting page, this is parameter that is passed under POST_DATA
-----------------------------256672629917035
Content-Disposition: form-data; name="upfile"; filename="image_file_name.jpg"
Content-Type: image/jpeg
So how is it possible to simulate a file upload of a input element in C#?
Look closely at the data that was posted, no directory is specified.
You can simulate any HTTP request through the HttpWebRequest object. Click here for an example.
When you're using the input type file element the browser is creating the request this for you. If you simply recreate this in HttpWebRequest you have full control over all aspects of the request and can modifiy as you wish.
It's probably in your interest to grab a copy of Fiddler.
If I understood your problem right,
you can't determine the directory of the file which was uploaded from your web browser control.
So ... it is impossible. The information about directory isn't given by browser - so it shouldn't be given by web browser control.
As MizardX suggested, it's better to send request using C#.
I'm trying to read the contents of an AJAX response in the WebBrowser control in C#/WinForms. The Navigating/Navigated/etc. events seem to fire, but they don't give any access to the data being returned.
Is there any way to intercept the requests and read the data?
Note: If I send the request directly (using webBrowser.Navigate(ajaxUrl)) the WebBrowser controls pops up asking the user to Open/Save the page (as it has a content-disposition header), so that isn't an option. I tried doing it manually with a WebClient/WebRequest, but I can't get the cookies to work correctly (the cookies I read from document.cookie do not seemto match the cookies actually sent with the AJAX request!).
No, you cannot capture XMLHTTPRequests from the web-browser control using the methods of the Web Browser control. You might want to have a look at http://www.fiddler2.com/core/
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.