12 Replies - 33357 Views - Last Post: 11 March 2010 - 11:33 PM Rate Topic: -----

#1 Stallion112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 17-June 03

Calling A Jscript Function Using An Httpwebrequest

Posted 10 February 2005 - 10:10 AM

I will try my best to explain my problem as clearly as possible.

Using VB.NET, I am sending a System.Net.HttpWebRequest to a specific page. I then retrieve the response, and when I am debugging, I can see the HTML code on the page that I have just gone to.

Ok, now with that said... on this page that I have just gone to, there is a button on the page. If you used a regular browser and were on this page and clicked the button, a javascript function is called. This function moves some values around into hidden fields on the page in a form. Then the function submits the form, taking the user to another page where the results of the form are displayed. The displayed HTML form results at this point is what I need to retrieve using a simple HttpWebRequest, not through
a browser window.

I would like to execute this javascript function using the HttpWebRequest if possible. I have tried for hours to create the correct URL with the right parameters that would duplicate the process of the javascript function.

To help describe my problem, the name of the function is called 'getData(0)'.
How can I call this function using System.Net.HttpWebRequest?

I don't know if it will help, but I will display the javascript function that I am trying to call.
Perhaps there is another path to my solution.




 	 function getData(index){
    setValues(index);
 
    if ((document.forms[1].FILEEXT.value == 'txt') || 
      ((document.forms[1].FILEEXT.value == 'afp') && 
       (document.forms[1]._afp.value=='html'))) {
 
        document.forms[1].actionpage.value='../cgi-bin/nodimage.cgi';
        document.forms[1].action='../html/users/userImage.jsp';
        document.forms[1].method='GET';
 
    }else {
 
      if(true){
      document.forms[1].actionpage.value='bookmarks/book.jsp';
      document.forms[1].action='../html/users/userImage.jsp';
      }else{
      document.forms[1].actionpage.value='../../servlet/imageClient';
      document.forms[1].action='../html/users/userImage.jsp';
      }
 
     document.forms[1].action='/myimage/servlet/ImageRequestServlet';
     document.forms[1].method='POST';
    }
    document.forms[1].toDo.value= 'GETDATA';
    document.forms[1].nsie.value=brwser;
    document.forms[1].conversionType.value=jpegval;
    document.forms[1].submit();
 	 }
 
 
 	 function setValues(index){
 
    document.forms[1].exts.value= document.forms[0].FILEEXT[index].value;
    document.forms[1].docs.value= document.forms[0].docs[index].value;
    document.forms[1].fieldValues.value= document.forms[0].fieldvalues[index].value;
    document.forms[1].tape.value= document.forms[0].tape[index].value;
   }



Is this even possible? Thank you.

Vincent

Is This A Good Question/Topic? 0
  • +

Replies To: Calling A Jscript Function Using An Httpwebrequest

#2 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Calling A Jscript Function Using An Httpwebrequest

Posted 10 February 2005 - 03:56 PM

Hmmm....please let me know if I've got the situation wrong. You want to send an HttpRequest to a specific page, and have the javascript on that page run as if you've submitted the form?

If this is correct, then you'll need to simulate a page submit...do you know if the HttpRequest is actually loading the page? If it is, the simple answer would be to submit the form at the end of the page load function, or have another javascript function that submits the page, thereby triggering your getData() function, see what I mean?

If I've gotten the situation incorrect, please let me know, and I'll suggest another way.
Was This Post Helpful? 0
  • +
  • -

#3 Stallion112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 17-June 03

Re: Calling A Jscript Function Using An Httpwebrequest

Posted 11 February 2005 - 08:51 AM

It seems you have the situation correct, however your suggestion seems a bit off.

See, I would like to perform this entire process in the backend, only to retrieve a .pdf file that is created from this other website. I do not have control of any of the code on this other website, I can only simulate URLs to navigate through their pages, passing along parameters that help build the page. I get so far on their website navigating this way, until I get to the very last page that demands submitting a form, but there is a javascript function on the page that correctly executes this submittal. I just need to call this function from the backend if possible.

My website is SiteA. SiteA pushes a button, and in the backend goes to SiteB, where I need to execute a script on that particular page (similiar to pressing the submit button on the page that calls a javascript function to submit their form properly). The result of that form submit will return me the results of an HTML page that contains a particular .pdf file that I will be retrieving back to SiteA to display. To the user on the front end, they don't even know that siteB exists.

:blink: This is driving me crazy and I can't figure out a way.

Hopefully you have a solution.. I am running out of options.

Thanks,

Vinnie
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Calling A Jscript Function Using An Httpwebrequest

Posted 11 February 2005 - 09:29 AM

Yeah, I did misunderstand, I thought you owned all the pages...the fact that you don't really does complicate things...essentially you need to send a submit command through the querystring...lemme look into it.
Was This Post Helpful? 0
  • +
  • -

#5 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Calling A Jscript Function Using An Httpwebrequest

Posted 11 February 2005 - 09:56 AM

Well, I hate to say this, but I don't believe you're going to be able to accomplish your goal using the method you've indicated. I've looked pretty closely at the HttpRequest object, and there is no way I can find to initiate or simulate a page submit through it.

If you had ownership of the page to be submitted, you could set up an event handler to look for incoming requests of this nature, and use that to trigger the submit, but since you don't have ownership or access, this can't be done (unless the owner agrees to let you set something up on his/her page).

You can try looking through the methods
here but I don't think it contains a way to submit through this object.
Was This Post Helpful? 0
  • +
  • -

#6 Stallion112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 17-June 03

Re: Calling A Jscript Function Using An Httpwebrequest

Posted 15 February 2005 - 08:52 AM

Thanks.

Do you think there is any other possible way besides using HttpRequest? I am willing to do anything to make this work.

If I can physically open up an IE window and go to this webpage, then press a button that calls a javascript function to perform a submit to the page, then I can't see why it isn't possible to execute the same thing programmically. Unless it just isn't possible. :(

Thanks again.
Was This Post Helpful? 0
  • +
  • -

#7 Stallion112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 17-June 03

Re: Calling A Jscript Function Using An Httpwebrequest

Posted 15 February 2005 - 08:56 AM

I just realized, by looking at your reply, that you have been searching the HttpRequest object... when in fact I am using the System.Net.HttpWebRequest object.

Here is the info on this object, maybe you will see something more clear than I can see:

See Here
Was This Post Helpful? 0
  • +
  • -

#8 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Calling A Jscript Function Using An Httpwebrequest

Posted 15 February 2005 - 08:57 AM

Stallion112, on Feb 15 2005, 10:52 AM, said:

If I can physically open up an IE window and go to this webpage, then press a button that calls a javascript function to perform a submit to the page, then I can't see why it isn't possible to execute the same thing programmically. Unless it just isn't possible. :(

You can do it programatically, but you need to own the page.

I'm not sure of another way to accomplish this.
Was This Post Helpful? 0
  • +
  • -

#9 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Calling A Jscript Function Using An Httpwebrequest

Posted 15 February 2005 - 09:28 AM

Stallion112, on Feb 15 2005, 10:56 AM, said:

I just realized, by looking at your reply, that you have been searching the HttpRequest object... when in fact I am using the System.Net.HttpWebRequest object.

Here is the info on this object, maybe you will see something more clear than I can see:

See Here

Well,,I've taken a look, and don't see anything right off hand that will do the job...I'll try and look further tonight when I get home.

I beleive we'll end up coming back to the ownership problem, however...event driven code can most likely NOT be simulated or inserted in third party pages..I'll keep looking, though.
Was This Post Helpful? 0
  • +
  • -

#10 polimorphims   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 29-March 05

Re: Calling A Jscript Function Using An Httpwebrequest

Posted 29 March 2005 - 10:21 AM

yes you can
basically the HttpWebRequest is a lib that trap http contenxt over a socket
the think that you need to do is simulate the action of your browser

you don't need to navigate over allt he pages ecxept if they have a authentication and in this case you need to trap the authentication cookie and add toy our headers on the request

ifthis is not the case only get the data and pass on the query string
in a get method

HttpWebRequest WEB_Request = (HttpWebRequest) WebRequest.Create( urlSteeps [ 0 ] );
WEB_Request.Method = "GET";
WEB_Request.ContentType = "application/x-www-form-urlencoded";
WEB_Request.KeepAlive = false;


is really easy
Was This Post Helpful? 1

#11 DanceInstructor   User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 18-March 05

Re: Calling A Jscript Function Using An Httpwebrequest

Posted 29 March 2005 - 12:16 PM

If you are going to call a Javascript function, you have to have something (like your web browser) for the javascript to run on. Maybe you realize this and I am being dense, but... It doesn't sound possible (unless ASP can execute javascript!).

Once you understand the javascript function, you could create your own form in ASP that mimics the origional javascript function.
Was This Post Helpful? 0
  • +
  • -

#12 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Calling A Jscript Function Using An Httpwebrequest

Posted 29 March 2005 - 12:35 PM

polimorphims, on Mar 29 2005, 12:21 PM, said:

yes you can
basically the HttpWebRequest is a lib that trap http contenxt over a socket
the think that you need to do is simulate the action of your browser

you don't need to navigate over allt he pages ecxept if they have a authentication and in this case you need to trap the authentication cookie and add toy our headers on the request

ifthis is not the case only get the data and pass on the query string
in a get method

HttpWebRequest WEB_Request = (HttpWebRequest) WebRequest.Create( urlSteeps [ 0 ] );
WEB_Request.Method = "GET";
WEB_Request.ContentType = "application/x-www-form-urlencoded";
WEB_Request.KeepAlive = false;


is really easy

I think what may be getting lost here is that the original user wanted to essentially submit a form on a page to which he has no access. It would be like programming a web page that presses the submit button on the Google homepage, and traps the result. Trapping the resulting page is not a problem, and javascript, or any other scripting language is not the problem. The problem is if you can effect a submit of a form on a page to which you have absolutely no access. I was not aware of one myself, but that doesn't mean it can't be done.

polimorphims, are you saying that through your method, the user can submit a form on a page hoe does not own or have access to? I know the result can be trapped without problem.
Was This Post Helpful? 0
  • +
  • -

#13 Guest_Gayatri*


Reputation:

Re: Calling A Jscript Function Using An Httpwebrequest

Posted 11 March 2010 - 11:33 PM

Hi

I want to call c# code in javascript in web application, i am new to this, please help.
My code
-------js----------
function Call_C_Code()
{
CodeBehind_Code();
}

-------C#----------
Public void CodeBehind_Code()
{
//I am inn
}
Was This Post Helpful? 0

Page 1 of 1