JavaScript - Form RRS feed

  • Question

  • Hi All...  How do you add a Name/Value header pair to a <form> request from JavaScript?  Like when the Submit button is pressed...  -- Curt

    Monday, February 1, 2010 12:53 AM


All replies

  • You could add a new input element to the form node from JavaScript and set the type to Hidden, then set the values as you please.
    Monday, February 1, 2010 6:34 PM
  • Thanks for the reply, Andy. 

    In production our application will be authenticated by a third party product - Site Minder.  In that environment, Site Minder will be passing information to our application through http headers.

    In a test environment though, we dont have that 3rd party product installed.  I was trying to create a "stub.aspx" page that would allow us to hand-peck that information into a form and then have the page add the info to the headers - so the app can find it.

    I've tried redirects, server-side transfers, and now a form submit all to no avail.  : (  The server-side transfer almost worked, but some ASP.Net AJAX code on the client was getting confused - apparently there's a path variable that retained the original stub page instead of the app's page...

    For the moment I'm putting some more code to the server - if it cant find the info in the headers, then it looks for it in the form's fields.

    Monday, February 1, 2010 6:43 PM
  • Hmm I'm not familiar with Site Minder, my understand is that you want:

    1) To have a web page where you can input custom information
    2) This information will then be submitted to a server where it will be added to HTTP headers and passing it to your web application? As a way of testing what site minder will do?

    Monday, February 1, 2010 7:00 PM
  • Correct.

    Site Minder is an ISAPPI add-on (extension I believe) that intercepts requests to web pages - in our case our application.  On the initial request to the application, Site Minder will intercept the request and put up its own logon page.  On submit it will then authenticate the credentials entered and then allow the original request to be served - HOWEVER, it will add some addition information - such as username - to the headers of that original request.

    Our application - which has no idea that Site Minder got in the middle - looks for that information in the headers.

    So my challenge is to emulate Site Minder in my own test environment.  Right now I'm using a <form> with its action set to our application's start page.  For that custom information I'm just putting it in a couple of fields.  I'd like to have that page put it in the headers, but I cant see how to do that.  So I've made changes to the application to pull the info from the <form> when it's running in the test environment...

    Monday, February 1, 2010 7:17 PM
  • You could use Fiddler which is a proxy to inject the headers you need, e.g. 
    Add a request header oSession.oRequest["NewHeaderName"] = "New header value"; OnBeforeRequest

    That way you don't have to code up a man in the middle server or the like. 
    • Marked as answer by CurtisDeHaven Monday, February 1, 2010 7:53 PM
    Monday, February 1, 2010 7:22 PM
  • WOW!  There's a cool idea.  Thanks.  I've never used Fiddler until last week when someone was helping me find a problem.  The person helping me showed me some of the ropes.   I'll take a look at that.  Thanks again.  : )

    Monday, February 1, 2010 7:53 PM