How to set a referer in C# using EO.WebBrowser

Looking for a solution to modify the referer in EO.WebBrowser. I know you can change the User-Agent using: webView1.CustomUserAgent, but it seems there isn't a direct method for changing the referrer. Are there any alternative approaches to achieve this, perhaps through JavaScript or another method?

I've tried capturing the beforesendheaders event with:

webView1.BeforeSendHeaders += new EO.WebBrowser.RequestEventHandler(webView1_BeforeSendHeaders);
, but it hasn't been very helpful.

I initially started working on a project with awesomium, but I encountered issues where some websites weren't loading and displaying only a blank screen. While I was able to change both the referer and user agent in awesomium, I require both functionalities to proceed.

Any ideas or suggestions would be greatly appreciated.

Answer №1

After some exploration, I managed to discover the solution by leveraging javascript. Below is the code snippet:

public partial class Form1 : Form
{
    private const string JS_referer_function = "function navigateToUrl(url) {var f = document.createElement(\"FORM\"); f.action = url; var indexQM = url.indexOf(\"?\"); if (indexQM>=0) { var params = url.substring(indexQM+1).split(\"&\"); for (var i=0; i<params.length; i++) { var keyValuePair = params[i].split(\"=\"); var input = document.createElement(\"INPUT\"); input.type=\"hidden\"; input.name  = keyValuePair[0]; input.value = keyValuePair[1]; f.appendChild(input); } } document.body.appendChild(f); f.submit(); }";
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        webView1.LoadUrlAndWait("http://referer.com");
        webView1.EvalScript(JS_referer_function);
        webView1.EvalScript("navigateToUrl(\"http://192.168.0.108/referer\");");
    }
}

This method involves initially loading , then utilizing javascript to navigate to while referencing as the referer.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React - Attempting to access property X from an undefined variable

Trying to access the string in section1.text, but my console is showing: https://i.stack.imgur.com/ox8VD.png Here's the JSX code I'm using: return ( <div> <h1>{this.props.article.title}</h1> ...

Assign a function in one class to be equivalent to a function in a different class

What is causing this issue and how should it be resolved? class A { constructor() { console.log('constructin A') } public someMethod = (x: string) => { console.log(x) } } class B { private myA: A constructor ...

Take action upon window.open

I have a code snippet here that opens a window. Is it possible to make an ajax call when this window is opened? window.open("http://www.google.com"); For instance, can I trigger the following ajax call once the window is open: var signalz = '1&apos ...

Encountering error while transferring information to ASP.NET using jQuery's Ajax() function

I'm attempting to transmit data to an ASP.NET program using jQuery with the following code: $.ajax({ method: "POST", dataType: 'json', url: "http://localhost:52930/api/person/", data: JSON.stringify({Name: "Sinan", Password: ...

The functionality of V-model is hindered when implementing Bootstrap Tokenfield

While working with Vue and Bootstrap Tokenfield, I encountered an issue where v-model was not functioning as expected. Let's say I have the following array: index variant_options 1 aaa 2 sss If I remove index 1, the result of inde ...

Making a dynamic accordion using JavaScript

I am currently coding in Javascript, without utilizing jQuery. Progress so far on the accordion title panel: var accordion = document.createElement('div'); accordion.className = 'panel-group'; accordion.id = 'accordion'; doc ...

Troubleshooting Socket.IO Communication: Client's emits not reaching server

I have implemented a real-time notification service in a web app using Express and Socket.IO. The client can successfully connect to the server and receive emits from it. However, I am facing an issue where the server is not receiving emits from the client ...

The dropdown feature in the bootstrap4 navbar causes the navigation items to shift and adjust their

I am currently working on a navigation bar using Bootstrap4 and I've added a nav-item button to dropdown a menu. However, the issue I'm facing is that when the menu drops down, it pushes other nav-items around, causing them to change position. Th ...

Creating a MySQL database dynamically in an ASP.Net application is a valuable skill to have

I am looking to dynamically create a MySQL database in ASP.NET (C#). My goal is to have the database created automatically when a user logs in, with the username saved in my server's App_Data folder. Since I am not familiar with MySQL databases, I wou ...

Restricting the number of characters allowed for text messages and keeping track of the count

I am attempting to implement a character limiter for an html textarea using JavaScript. Additionally, I want to include a total character counter. Unfortunately, the code I have written isn't functioning as expected. Can anyone identify where my mist ...

What is the best way to convert all the values from a dropdown list into Million or Billion using JavaScript?

Is there a way to convert the output numbers on the dropdown generated by this code into abbreviated formats, like in the examples below? (Example 1: If the output number is 1000000, I want it to show as 1M (million). Example 2: If the output number is 100 ...

How can I identify an event occurring on two sibling elements that are overlapping?

I have 2 overlapping siblings as shown below: document.querySelector("#item1").addEventListener('mouseup',()=>{ console.log("Mouseup item 1!"); }); document.querySelector("#item2").addEventListener('mouseup',()=>{ console. ...

"Refresh your Backbone app by hitting the Enter key and watch as a new

When I click [edit] (after already committing a word/definition), my goal is for the updateOnEnter method to save the changes made to the definition field, lose focus, and make the field uneditable. However, when I press Enter, the cursor unexpectedly move ...

Senecajs responded with a result that was neither an object nor an array, displaying a Promise

Seeking guidance on incorporating promises into my Seneca modules. Firstly, there is the server.js file that exposes a route: var express = require('express'); var app = express(); var Promise = require('bluebird'); var seneca = requ ...

The hue of the knob is unchangeable once the server data request is made

Upon receiving data from the server request, I am unable to update the color of the knob to match the image provided at this link screencast. Below is my code: JavaScript Code $scope.options = { /* knob option */ }; $http .get(url) .then(functio ...

When using the Three.js FBX loader to add objects to the scene, the newly added objects may not be present in the children array

After following the example provided on threejs.org for loading FBX files, I managed to successfully load my model using the function below: this.obj = null; var loader = new THREE.FBXLoader(); var objs = [] function load_init( object ) { mixer = ne ...

Catch the return of the transition event

My website is built on asp net core, with all pages displayed as partialviews to create a spa model without relying on angular or other frameworks. By switching partialviews, I can easily modify the page's url using window.history.pushState ("objec ...

Utilizing TypeDoc to Directly Reference External Library Documentation

I am working on a TypeScript project and using TypeDoc to create documentation. There is an external library in my project that already has its documentation. I want to automatically link the reader to the documentation of this external library without man ...

Update web page content using JavaScript onClick

I'm trying to figure out how to refresh my page every time a door is clicked. Can anyone help me with where I should add window.location.reload(); in my code? Here's the link to my pen: https://codepen.io/tacodestroyer/pen/bROpeQ function open ...

What is the best way to retrieve a single result from a JavaScript for loop?

I've been working on a small JavaScript Zombie game using the p5 library. The goal is to keep track of hits when clicking on a Zombie and misses when failing to hit one. However, I'm facing an issue where 10 results are displayed per click when t ...