I would like to know to know how to download HTML code from a webpage in Xamarin. The webpage is opened on a Android device and requires login, therefore it cannot be downloaded using a url link in WebClient. I am interested if the is a possibilty to download the HTML code from the opened webside, so that it can be used to notify me about changes in the webside.
My code to open the webside (then i need to log in):
void WebViewFunction()
{
webView1 = FindViewById<WebView>(Resource.Id.webView1);
webView1.Settings.JavaScriptEnabled = true;
webView1.SetWebViewClient(new Client());
webView1.LoadUrl($"https://www.strava.cz/Strava/Stravnik/Prihlaseni");
}
I have absolutely no idea how to do it since I am a beginner.
Thanks for your answer.
Related
So I've been trying to download a file from MediaFire using WebClient.DownloadFile(), but all files I download do not work properly. I've tried to download PDF files and PNG files, none of them open correctly in their respective software. I'm using this for a WinForms desktop application. I've already searched for multiple solutions but none of them apply to my situation.
This is the code I've used:
private void downloadFile(string url, string filename)
{
var client = new WebClient();
client.DownloadFile(url, filename);
}
I'm a begginer so any help is appreciated!
I found the solution myself with some help from Jimi.
I needed to find the link the page was using for the download process, not the link to the page itself. I did this by accessing the code of the page using the inspect tool and finding the direct link to the file, then using my previous method it worked just fine.
I coded an app and I am trying to download a apk from my webspace now. I googled the whole day now and everything I found was for Java I think, but I need C#.
This is what I found (not only this but it's an example): Downloading APK from server and installing it to device (but it's not working I don't know why).
But I have some problems with the code. I can't use the setRequestMethod or getinputstream etc.
Then I tried out this because it seemed to be much easier:
WebClient webClient = new WebClient();
Uri newUri = new Uri("http://mywebspace.bplaced.net/AppDownload.apk");
webClient.DownloadFile(newUri,Path.Combine(Android.OS.Environment.DirectoryDownloads, "AppDownload.apk"));
This is also not working. I'm getting the message "parts of the path not found" (kinda like this, my Visual Studio isn't in English). Doesn't matter what I enter as my path.
This seems to be a duplicate question, which already has been answered here: How to download a file from a URL in C#?
Nevertheless, I have tested your code and for me it is working. I am able to download a file from an url. So, my guess is, that you have a typo in your URL, a problem with the firewall, etc.
Please copy the URL you have entered in the source code and paste it to a Browser of your choice. And see if the download starts. Just to be sure that the URL is correct.
It would better to provide us with the whole error message.
So this is a bit of a tricky problem I'm having and I'm starting to think that it's not easily possible.
There's a website that has a level of security that I am trying to automatically download files from(it's a banking site). The website will not save user info when you log in, and after logging in you have to verify a certificate in your browser to receive your reports. Once you've verified the browser with the certificate and are logged in, however, you are free to open up the reports(pdf files) by directly typing in the link to them.
For other sites, I would do something like:
using (WebClient client = new WebClient())
{
client.DownloadFile(PDFFileReportWebsite,#LocalLocationToStoreFile);
}
But for this site, I have no idea what to do(the above doesn't work). Is there a way to have code like above run from within the browser itself after I've logged in and verified my certificate?
One solution I thought of that would be overkill(nevermind just gross/hacky), and I can't imagine the best option, would be to make a webbrowser app in C# and run the code on that browser after logging in.
EDIT:
ProcessStartInfo pi = new ProcessStartInfo(WebAddressOfPdfFileINeed);
Process.Start(pi);
correctly opens up the webbrowser(chrome since its my default) to the file I need(If I'm already logged in and verified my cert). Is there a way to force chrome to save this file or print it as text or a pdf?
I am making a game for my windows phone, using Visual Studio 2012 for Windows Phone and it went good from there, I wrote a few classes, and added assets but I encountered a problem.
I wanted to make a bug request / idea method, but no-where could I find where to email with XNA. I searched on Google but it came up with stuff like "How to use XNA game studio" and at the bottom it said stuff like "email us" so I never found it out. Basicley I couldn't find it. Can anyone help me out?
You can send an email out using the EmailComposeTask class in WP8. But it not totally automatic, the user has to select the account to send the email with then the Email display pops up then they have to click on send button. You can try it like this:
How to use the email compose task for Windows Phone 8
using Microsoft.Phone.Tasks;
// do this when the page has load completely (not in the constructor)
EmailComposeTask emailComposeTask = new EmailComposeTask();
emailComposeTask.Subject = "message subject";
emailComposeTask.Body = "message body";
emailComposeTask.To = "recipient#example.com";
emailComposeTask.Cc = "cc#example.com";
emailComposeTask.Bcc = "bcc#example.com";
emailComposeTask.Show();
However, I don't think this is what you want. What I would do instead because it's difficult to do the email thing silently is create a webpage, that you can POST to. You then can just open a WebClient and POST the data that you need to that website. Then on the website's back end, just decode the POST[DATA] into a database.
Hope this helps you, good luck.
As mentioned in the other answer, you may want to consider just opening a web page with a form for them to fill out, rather than writing emails within your app.
If so, here is the code to open a webpage on Windows Phone from an XNA game (using http://www.google.com/ as an example.:
WebBrowserTask browser = new WebBrowserTask();
browser.Uri = new Uri("http://www.google.com/", UriKind.Absolute);
browser.Show();
I am using a WinForm webbrowser, i load an local html file which contains and flash player that plays a video but the problem is that the player works but the video is not loaded.
When i open the html file in a browser it works fine.
Here is the code i am using:
string curDir = Directory.GetCurrentDirectory();
this.webBrowser1.Url = new Uri(String.Format("file:///{0}/Resources/streaming.html", curDir));
The file location is correct, is there anything i can do to solve the problem ?
Try explicitly disabling the following Browser Features for your WebBrowser-based app: FEATURE_LOCALMACHINE_LOCKDOWN, FEATURE_BLOCK_LMZ_OBJECT, FEATURE_BLOCK_LMZ_SCRIPT. You could reuse some code from here.