Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 31st, 2006, 06:27 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Default Mimic the FORM POST

Is it possible to mimic the POST method of the FORM in HTML using XMLHTTP (or similar) so that I can capture the returning webpage in a textstream to pull out information that I need?

Cross domain security is set so that I cannot create, manipulate or control the pages in HTML format, so seeking a reasonable alternative.

Any help appreciated... and this is where I have started.


Dim sWebsite

sWebsite = "http://...../"

Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")


    ' *** FORM CONTENT ***
    ' <FORM name='Contact' method='POST' action='Login.asp'>
    ' <INPUT name='Organise__Recnum' type='hidden' value='0'>
    ' <INPUT name='Contacts__Recnum' type='hidden' value='0'>
    ' <INPUT name='ChangedStates' type='hidden' value=''>
    ' <INPUT name='Contacts__Logon_No' type='text' value='0000'>
    ' <INPUT name='Contacts__Password' type='password' value='00000000'>
    ' </FORM>

    xmlhttp.open "POST", sWebsite & "Login.asp", False

    xmlhttp.send

    Response.Write xmlhttp.responseText

Set xmlhttp = Nothing

Regards,

Sean Anderson
__________________
Regards,

Sean Anderson
 
Old October 31st, 2006, 08:13 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You can add a button to your page and wire its onClick event to some AJAX and then you can grab all of your form values; as long as you don't call form.submit() the page will never post.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 31st, 2006, 09:51 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think that you may have my scenario muddled.

My page (http://localhost/test.asp) is to submit the information to someone else's page (http://someone/login.asp) and I want to interrogate the HTML that is returned; because it contains a second form that has session specific information that I need.

Hope that this makes sense.

Regards,

Sean Anderson
 
Old October 31st, 2006, 10:01 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Now you have lost me. I understand that you are posting to http://someone/login.asp and, as i understand, you are passing some sort of variables via the querystring to that site, is it also correct that the second domain is going to be returning HTML to your domain?



-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 31st, 2006, 10:11 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If I go to the login.asp page, there is a form (content as shown in my opening message, with a submit button, too, of course).

Yes, the second domain (out of my control) will return HTML that contains a new form where you select your location ... but also has values in hidden INPUTS, which I need in order to submit to the next page.


Regards,

Sean Anderson
 
Old October 31st, 2006, 10:58 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok, I see what you are trying to do. Yes this should be possible using the XMLHttp object on the server side though, I am not sure how your response is going to come back.

I do the same thing you are asking when connecting to UPS's Shipping APIs but I know exactly what format I am getting back (XML) so that it is structured a certain way and I can parse it effectively. You are going to have to write a text parser that will parse your request to grab the values you need while, at the same time, preserving the data so that it can still be displayed by the browser.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 31st, 2006, 11:11 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Indeed, I have the XMLHTTP at server side and would seem (from today's investigations) that I need:

xmlhttp.open "POST", "http://url/login.asp", False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send "Contacts__Password=00000000&Contacts__Logon_No=00 00"

When I examine the content of the xmlhttp.responseText it appears to be the same page (ie. not logged in) ... wonder if it's likely that they are checking for this approach to their pages?

I have no idea of the exact format of what would come back from the login.asp page, but based on the style of coding that I have seen so far, would expect it to be nothing more than some basic HTML coding.

Regards,

Sean Anderson
 
Old October 31st, 2006, 11:23 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Well, what you are asking is a little bit more involved.

Here is why. You collect some sort of creditnals on your page (lest say username and password) and then you need to, really, supply that information to the login.asp page and then raise THAT pages form handler. (I am guessing here, but based on what you have said that seems likely, that the login.asp page has both a username and password field on it as well)

So, your xml request IS working, you are posting to that page but there is nothing on that page to handle your post so you are getting the default page. hth.



-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old November 23rd, 2006, 05:57 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 114
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A bit more patience and a lot of double checking for spellings and it does work.

xmlhttp.open "POST", "http://url/login.asp", False
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send "Contacts__Password=00000000&Contacts__Logon_No=00 00"

The content of the HTML on the "http://url" server will now be captured by the xmlhttp.ResponseText, which I can manipulate and display as I wish.

Downsides to this are that even the slightest change of spelling on the "http://url" server for the names of the fields in forms and my page(s) will fall over. This will be a pain as I am writing the code not only into pages that will appear on webservers throughout the UK, but into a DLL that will be installed throughout the UK ... all of which will need updating in such a scenario, until I can convince these people to open up an XML interface.

Ho, fun, huh.

Thanks for the input from everyone on this.

Regards,

Sean Anderson





Similar Threads
Thread Thread Starter Forum Replies Last Post
Submitting POST data without a form takabyte Classic ASP Basics 15 April 28th, 2014 01:44 AM
Why does the form always post back? Conch General .NET 9 January 9th, 2007 04:12 PM
I am interested to mimic Windows Magnifier guntank C# 2005 0 September 25th, 2006 01:39 AM
Using XMLHTTP to POST form data channer Classic ASP XML 8 January 6th, 2004 05:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.