In the app I'm working on, I want to be able to open the webbrowser and navigate to a specific URL.
This is easy enough using the WebBrowserTask, but the URL I want to reach requires a couple of request headers.
I haven't been able to figure out how to achieve this, and is of course hoping someone here can point me in the right direction, or even show an example.
If the task it self doesn't support headers, is there any other way?
EDIT:
Well I found out that the WebBrowserTask in its current state does not support adding headers.
My solution was to make a new XAML page in the app and add a WebBrowser control as the only object.
The webbrowser control supports adding headers like this:
Uri uri = new Uri("http://YOUR_URL.COM");
string headers = String.Format("HEADER1:{0}\r\nHEADER2:{1}\r\nHEADER3:{2}\r\n", projectId, username, password);
webBrowser.Navigate(uri, null, headers);
The important part of adding the headers is to remember to seperate the headers with \r\n
Related
I'm working on a UWP app and have a page with a WebView. In the WebView I need to set the user-agent to a custom value.
I have tried the following:
var requestMessage = new HttpRequestMessage(HttpMethod.Get, baseUri);
requestMessage.Headers.Add("User-Agent", "MyCustomValue");
webview.NavigateWithHttpRequestMessage(requestMessage);
However the WebView doesn't use my custom user-agent but instead use the original default value of the user-agent. This is confirmed by this thread at MSDN.
Any good input to alternative solutions or workarounds is appreciated.
It seems only to be supported when doing POST, not GET.
Perhaps this blog post can get you closer to a solution: https://basquang.wordpress.com/2014/04/26/wp8-1-changing-windows-phone-8-1-webview-default-user-agent-in-all-outbound-http-requests/
Try it:
var rm = new Windows.Web.Http.HttpRequestMessage(HttpMethod.Get, new Uri("https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending"));
rm.Headers.Add("User-Agent", "test");
rm.Headers.Add("NSASESSIONID", "CA79AB9B-21CD-43BE-A48A-49B5F1289D22");
WebView.NavigateWithHttpRequestMessage(rm);
It's working for me.
I'm trying to capture and handle every single request a web page, or a plugin in it is about to make.
For example, if you open the console, and enable Net logging, when a HTTP request is about to be sent, console shows it there.
I want to capture every link and call my function even when a video is loaded by flash player (which is logged in console also, if it is http).
Can anyone guide me what I should do, or where I should get started?
Edit: I want to be able to cancel the request and handle it my way if needed.
You can use the Jetpack SDK to get most of what you need, I believe. If you register to system events and listen for http-on-modify-request, you can use the nsIHttpChannel methods to modify the response and request
let { Ci } = require('chrome');
let { on } = require('sdk/system/events');
let { newURI } = require('sdk/url/utils');
on('http-on-modify-request', function ({subject, type, data}) {
if (/google/.test(subject.URI.spec)) {
subject.QueryInterface(Ci.nsIHttpChannel);
subject.redirectTo(newURI('http://mozilla.org'));
}
});
Additional info, "Intercepting Page Loads"
non sdk version and with much much more control and detail:
this allows you too look at the flags so you can only watch LOAD_DOCUMENT_URI which is frames and main window. main window is always LOAD_INITIAL_DOCUMENT_URI
https://github.com/Noitidart/demo-on-http-examine
https://github.com/Noitidart/demo-nsITraceableChannel - in this one you can see the source before it is parsed by the browser
in these examples you see how to get the contentWindow and browserWindow from the subject as well, you can apply this to sdk example, just use the "subject"
also i prefer to use http-on-examine-response, even in sdk version. because otherwise you will see all the pages it redirects FROM, not the final redirect TO. say a url blah.com redirects you to blah.com/1 and then blah.com/2
only blah.com/2 has a document, so on modify you see blah.com and blah.com/1, they will have flags LOAD_REPLACE, typically they redirect right away so the document never shows, if it is a timed redirect you will see the document and will also see LOAD_INITIAL_DOCUMENT_URI flag, im guessing i havent experienced it myself
I'm new to Windows phone 7 application development. I'm currently developing an app in which I wish to do a HTML request and display the result obtained in Web browser. For example, Suppose I give the below URI
"http://m.imdb.com/find?q="+search_string (where search_string is a variable)
I want to take the result obtained from this and display it on the web browser. I've been searching regarding this for past 1 day... Didn't get any fruitful results. So please redirect me either to a suitable tutorial page or please give a sample code?
WebBrowserTask wbt = new WebBrowserTask();
wbt.URL = "http://m.imdb.com/find?q="+search_string
wbt.Show();
this will allow you to launch the url in the browser.
WebBrowserTask
I have a client who makes Flash AS2 based language learning software.
They wanted to add a bug report email to the apps.
It is dead simple if you don't mind the swf's post opening a new tab:
on (release, releaseOutside) {
var my_Var:LoadVars = new LoadVars();
my_Var.brsub = subject.text;
my_Var.brmsg = message.text;
my_Var.send("bug_report.php", "_blank", "POST");
}
I am looking for docs or an example in AS2 of making this post via AJAX and not opening the new tab.
Anyone know where I can read up on it. I know it must be out there but my Googling has come up empty.
You don't need to make an AJAX Request in Flash to process that request:
you can use the loadVariables method to send data via POST, without leaving your Flash movie:
Adobe Help Reference
HI, is possible to add request headers in WP7 WebBrowser control?
There is no way to do this. If you need to change headers you'll need to use HttpWebRequest.
You could intercept the requests from the WebBrowser control and make them yourself via HWR but this could get complicated very quickly.
No - I don't think there's any API hook available for this.
It's a similar problem to the "change the user agent" request discussed in Bring back mobile version of website in WebBrowser control for wp7?
Sorry to necro but the answers here are wrong. Headers can be added to a WebBrowser through the Navigate method.
WebBrowser.Navigate(YourURI, null, YourCustomHeaderString)
See this page: http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff626636(v=vs.105).aspx
.
These headers will only apply to the first page navigated to through your code. If you want the headers to stay the same even when users click a link inside the web browser control, add this for the WebBrowser's navigating event:
private void browser_Navigating(object sender, NavigatingEventArgs e)
{
string url = e.Uri.ToString();
if(!url.Contains("YESHEADERS"))
{
e.Cancel = true;
string newUrl;
if(url.Contains("?"))
{
newUrl = url + "&YESHEADERS";
}
else
{
newUrl = url + "?YESHEADERS";
}
browser.Navigate(newUrl, null, "fore:" + Variables.GetForeground() + "")
}
}
Here's what that does:
We create an indicator, YESHEADERS, that tells us whether or not we have added custom headers.
When the WebBrowser tries to Navigate, we check whether or not the URL it is navigating to, e.Uri, contains YESHEADERS.
If it does, we've already added our headers. Take no action
If it does not, cancel the current navigation. Create a new URL equal to the old URL plus our indicator. We add YESHEADERS on to the new URL in it's query string. If you are not familiar with query strings that is fine, just know that they are extra strings on the URL that have no effect in our case. About Query Strings
Then, we navigate to the new URL, and add our custom headers.
In short, if we have our indicator YESHEADERS the web browser knows that we've added our custom headers, if we don't have YESHEADERS, than the web browser needs to add the headers.