Modify Http Request Header using JavaScript

Hi,

    The question might look trivial to many of you, anyway can you guys provide with a Yes/No answer along with some reasoning.

1. Can we modify the HttpRequest on client side by using Javascript to append our custom httpheaders to the request.

2. Is there any other way to append custom httpheaders to the request from the client side?

 -Amrish 


 

0
amrish_deep
12/6/2007 6:30:22 AM
asp.net.client-side 24353 articles. 1 followers. Follow

1 Replies
772 Views

Similar Articles

[PageSpeed] 45

Hi,

Thank you for your post!

Can we modify the HttpRequest on client side by using Javascript to append our custom httpheaders to the request.

See Setting HTTP request headers

Example Code

var headerName  = "X-hello";
var headerValue = "world";

function LOG(text)
{
// var consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
// consoleService.logStringMessage(text);
}

function myHTTPListener() { }

myHTTPListener.prototype = {

observe: function(subject, topic, data)
{
if (topic == "http-on-modify-request") {

LOG("----------------------------> (" + subject + ") mod request");

var httpChannel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
httpChannel.setRequestHeader(headerName, headerValue, false);
return;
}


if (topic == "app-startup") {

LOG("----------------------------> app-startup");

var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);

os.addObserver(this, "http-on-modify-request", false);
return;
}
},

QueryInterface: function (iid) {
if (iid.equals(Components.interfaces.nsIObserver) ||
iid.equals(Components.interfaces.nsISupports))
return this;

Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
return null;
},
};

var myModule = {
registerSelf: function (compMgr, fileSpec, location, type) {

var compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
compMgr.registerFactoryLocation(this.myCID,
this.myName,
this.myProgID,
fileSpec,
location,
type);


LOG("----------------------------> registerSelf");

var catMgr = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
catMgr.addCategoryEntry("app-startup", this.myName, this.myProgID, true, true);
},


getClassObject: function (compMgr, cid, iid) {

LOG("----------------------------> getClassObject");

return this.myFactory;
},

myCID: Components.ID("{9cf5f3df-2505-42dd-9094-c1631bd1be1c}"),

myProgID: "@dougt/myHTTPListener;1",

myName: "Simple HTTP Listener",

myFactory: {
QueryInterface: function (aIID) {
if (!aIID.equals(Components.interfaces.nsISupports) &&
 !aIID.equals(Components.interfaces.nsIFactory))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
},

createInstance: function (outer, iid) {

LOG("----------------------------> createInstance");

return new myHTTPListener();
}
},

canUnload: function(compMgr) {
return true;
}
};

function NSGetModule(compMgr, fileSpec) {
return myModule;
}
 
Is there any other way to append custom httpheaders to the request from the client side? 
 As far as I know, no other method to do this.
If you have further questions, let me know.
Best Regards, 

Sincerely,
Jin-Yu Yin
Microsoft Online Community Support
0
Jin
12/12/2007 7:04:39 AM
Reply:

Similar Artilces:

How to use client-side script(javascript) in DNA using .Net Remoting
Hi all,     It was known that SAO and Singleton object about .Net Remoting. When I Create an object in server side and hosting in IIS's virtual directory,I want to use javascript asynchronous invoking the remote object by HTTP channel, 80 port and SOAP formatter just like XMLHTTP invoking web service. My code as following, <script> objXmlDoc = new ActiveXObject("Msxml2.DOMDocument"); objHttp = new ActiveXObject("Msxml2.XMLHTTP"); strEnvelope = ?? objHttp.onreadystatechange = function() { ...... }   szUrl = "http://ServerNa...

How to use client-side script(javascript) in .Net Remoting
Hi all,     It was known that SAO and Singleton object about .Net Remoting. When I Create an object in server side and hosting in IIS's virtual directory,I want to use javascript asynchronous invoking the remote object by HTTP channel, 80 port and SOAP formatter just like XMLHTTP invoking web service. My code as following, <script>  objXmlDoc = new ActiveXObject("Msxml2.DOMDocument"); objHttp = new ActiveXObject("Msxml2.XMLHTTP"); strEnvelope = ?? objHttp.onreadystatechange = function() { ......  }    szUrl = &...

How to write data to a file in client side using javascript or someother client side scripting language.
Hi, I would like to know how to write a data to a client side file using javascript or someother client side scripting language. The file type expected is ini file. txt file would also be appreciable. Thanks in advance.   If the site is a trusted and you are running IE then you could try http://www.w3schools.com/asp/asp_ref_filesystem.asp The Old Sewing FactoryThat twitter nonsense. You can write to the server, but not to the client's machine.  Being able to do so would be a huge security breach.When you ask a question, remember to click "mark as answered"...

Can I get the HTTP request size from client side javascript?
Hi all, This is a tricky one - I have a a .Net web page that allows users to upload MP3 files via an <input type="file" ... > control. Since I have an upload file limit of 12MB per file I want to try and work out on the client side (when the user clicks the "upload file" submit button) how big the request that is being sent to the server is so I can stop an upload larger than 12MB - is this possible? Can you access the HTTP request info in Javascript or would that break the security model for Javascript? Hope someone can help - got a horrible feeling the a...

In datawindow.net,access the database from client side event using javascript
In powerbuilder,for example,a datawindow has two columns:itemno,description. input an itemno,validate it.if not found from the database,return 1 to trigger itemerror event; if found,get the description of the item from the database,and fill it into the column "description". The question is how to fulfill the function in web datawindow,through web service? if so,I need an example to realize it. You will need to use AJAX or make a round trip on item change event. -- Dean Jones CEO PowerObjects http://www.powerobjects.com (612) 339-3355 Ext. 112 TeamSybase * *...

How to use HTTP protocol in .Net Remoting? Thanks and Regards,How to use Http protocol in .net Remoting
<>Hi,     <><>How to use HTTP protocol in .Net Remoting ? Is there any specific code bits requires for that ?    I am using TCP protocol it's working but when i change it to  HTTP it throwing an error like "Arugument null exception"<>  Could  anybody give samples for that? Thanks & Regards,Vijay Here is an example of HTTP remoting:http://msdn2.microsoft.com/en-us/library/system.runtime.remoting.channels.http.httpchannel.aspxCheers,       Kev...

When to use client side varidation and server side varidation in .net?
In .net or classic web application we can varidate user data either on client isde or server side. How to select which side varidate to be used? Thanks! Generally, I use both client and server validation. I make sure the input is in the correct format and reasonably valid on the client, then I verify the data on the server. The extent of validation also depends on the type of data that I need to validate.Here are a few references:Validating ASP.NET Server ControlsIntroduction to Validating User Input in Web FormsClient-Side Validation for ASP.NET Server ControlsSecurity Checklist...

how do i get selectedValue of drop down list server side if i am populating it using client side javascript?
 Hi All.I am populating a drop down list client side using: The drop down list is populated based on a selection of another drop down list. ddlList.options[i] = new Option(1,2); as an exampleThe populating is done as i need it to. However, a button click event i am trying to get the selectedValue of the ddlList. However, it doesn't give me it. It only gives me the selectedValue of the drop down list on first rendering. Any ideas on how i can get it?   Could You paste some code? That would be helpful. Thanks S@ss (Shashi Shekhar Singh)My BlogPlease mark a post as ANSWER ...

client-side Javascript HTTP
Hello, Does anyone out there know if there's a way for client-side Javascript to fetch a text file via HTTP and read its contents into a variable? The best I can do so far is creating an IFRAME element (via DOM), which does display the text I want, but from there I can't find a way to read the frame's contents into a veriable. Sorry if this is the wrong NG for this question; if there's a better one, I'm happy to post there. Thanks! regards, -Felipe Gasper Felipe Gasper wrote: > Does anyone out there know if there's a way for c...

superreview requested: [Bug 278821] Access key conflict in Preferences->Advanced->HTTP Networking: both Use HTTP 1.1 and Help use 'H' : [Attachment 171622] Fixed accesskey for Use HTTP 1.1 (H -> E).
Giacomo Magnini <giacomo.magnini@portalis.it> has asked neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> for superreview: Bug 278821: Access key conflict in Preferences->Advanced->HTTP Networking: both Use HTTP 1.1 and Help use 'H' https://bugzilla.mozilla.org/show_bug.cgi?id=278821 Attachment 171622: Fixed accesskey for Use HTTP 1.1 (H -> E). For visibility reasons, I've also changed 2 other accesskeys: Enable Keep-Alive (L -> A) and Enable Pipelining (I -> N) https://bugzilla.mozilla.org/attachment.cgi?id=171622&action=edit ...

Modify Request Headers with HTTP module?
HiI need to authenticate a flash client. Flash is limited in what I can programmatically set in terms of HTTP headers etc. I planned to pass in the ASP.NET session id into the flash control. The flash control would then make a request to a .NET webservice. I need to pass the sessionid from the flash client to the server. I then need to check that the session is valid on the server.My idea was to create an HTTP module which would look for the sessionid (passed as part of the SOAP request, or otherwise). It would then ADD an HTTP header to the request "ASP_sessionid" or whatever, with the sess...

.Net varible into client side JavaScript
I'm need to get a variable from my web app and place its value in a JavaScript. I tried doing this with a Label but I get the HTML included. I don't think I can use the <%# %> from classic ASP? Anyone have any ideas on how they would approach this problem? tbone_stl wrote:Anyone have any ideas on how they would approach this problem? Hi, and welcome to the ASP.NET forums. It's possible to pass a variable to a javascript function. I created a small coding snippet: <%@ Page Language="C#" %>   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http...

How -to use Client-Side Javascript example?
Can someone please point me to a good example of how to do this? Sorry, but I'm a PowerBuilder developer and still don't understand this. How can you code a javascript file to get data from the webform, use that data, and set a result back to the webform? A small example of coding the itemchanged event would be great. In my app, the user's want to be able to enter data in a field and have that trigger calculations that would populate other fields. Can someone give me or point me to a good example of how to do this? Thanks Jay Hi, Jay Read my answer in the threa...

focus event using http request or xml request using javascipt
i want lost focus event using http request or xml request using javascipt how to call code file (.cs file) using ajax and javascript i have one asp.net server control  Nothing is really over,untill the moment stop trying for it...Amitsp(MCTS,MCP)sqlreporting.blogspot.com You can capture the event in the javascript and then call the cs function in the page from the javascript. You can also call the button in the page (with style=display:none) . In the javascript you can call the click event of the button which will call the server side code.Vikram www.vikramlakhotia.comPlease mark the...

Web resources about - Modify Http Request Header using JavaScript - asp.net.client-side

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

Lightbox (JavaScript) - Wikipedia, the free encyclopedia
On a Lightbox-enabled page, a user can click an image to have it magnified in a Lightbox window, which resizes itself according to the size of ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
about dmoz - help Top : Computers : Programming : Languages : JavaScript : Tools : Obfuscators Tools for obfuscation/compression JavaScript code. ...

Facebook File-Transfer App Pipe Relaunches, Now Works Via JavaScript, WebRTC
... allowed Facebook users to send and receive files up to 1 gigabit in size. A new version of Pipe debuted Monday, and the app now works via JavaScript ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

JavaScript SDK - Facebook-Entwickler
Overview The JavaScript SDK provides a rich set of client-side functionality for accessing Facebook...

Senior Front-End Developer (Javascript and AJAX)
Company: Sometrics Category: Software Development Location: Los Angeles, CA How to Apply: jobs@sometrics.com Description: We are looking for ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken . blog.mozilla.org/research/2014/… ...

Resources last updated: 12/30/2015 5:04:06 AM