Simulate form post from Server Side

Discussion in 'ASP General' started by BarryX, Sep 26, 2007.

  1. BarryX

    BarryX Guest

    Hi,

    How do I simulate this from the server side:

    <form name="SearchForm" method="POST" id="SearchForm"
    action="http://SOMEURL/Search.ASP?Parm1=1&Parm2=2">

    I have generally been posting data using:

    Set xml = Server.CreateObject("Microsoft.XMLHTTP")
    xml.Open "POST","http://SOMEURL/Search.asp?" & strParmList, False
    xml.Send

    The above is fine for passing URL parameters, but I need to simulate it
    coming from a form which has a name. How do I pass the form name which
    is used at the posted URL?

    Help!
     
    BarryX, Sep 26, 2007
    #1
    1. Advertising

  2. BarryX

    Tim Slattery Guest

    "BarryX" <> wrote:

    >Hi,
    >
    >How do I simulate this from the server side:
    >
    ><form name="SearchForm" method="POST" id="SearchForm"
    >action="http://SOMEURL/Search.ASP?Parm1=1&Parm2=2">
    >
    >I have generally been posting data using:
    >
    > Set xml = Server.CreateObject("Microsoft.XMLHTTP")
    > xml.Open "POST","http://SOMEURL/Search.asp?" & strParmList, False
    > xml.Send
    >
    >The above is fine for passing URL parameters, but I need to simulate it
    >coming from a form which has a name. How do I pass the form name which
    >is used at the posted URL?


    AFAIK, the "name" attribute of a form tag really has no meaning and is
    never transmitted to the server. On a normal HTML page, if you want to
    send an extra bit of data you use a <input type="hidden" > element.

    --
    Tim Slattery
    MS MVP(DTS)

    http://members.cox.net/slatteryt
     
    Tim Slattery, Sep 26, 2007
    #2
    1. Advertising

  3. BarryX wrote:
    > Hi,
    >
    > How do I simulate this from the server side:
    >
    > <form name="SearchForm" method="POST" id="SearchForm"
    > action="http://SOMEURL/Search.ASP?Parm1=1&Parm2=2">
    >
    > I have generally been posting data using:
    >
    > Set xml = Server.CreateObject("Microsoft.XMLHTTP")
    > xml.Open "POST","http://SOMEURL/Search.asp?" & strParmList, False
    > xml.Send
    >
    > The above is fine for passing URL parameters, but I need to simulate
    > it coming from a form which has a name. How do I pass the form name
    > which is used at the posted URL?
    >


    1. In server-side code, use Microsoft.ServerXMLHTTP
    2. I don;'t think this is possible due to security restrictions. What
    are you trying to accomplish?


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Sep 26, 2007
    #3
  4. BarryX

    Evertjan. Guest

    Bob Barrows [MVP] wrote on 26 sep 2007 in
    microsoft.public.inetserver.asp.general:

    > BarryX wrote:
    >> Hi,
    >>
    >> How do I simulate this from the server side:
    >>
    >> <form name="SearchForm" method="POST" id="SearchForm"
    >> action="http://SOMEURL/Search.ASP?Parm1=1&Parm2=2">
    >>



    > 1. In server-side code, use Microsoft.ServerXMLHTTP
    > 2. I don;'t think this is possible due to security restrictions. What
    > are you trying to accomplish?
    >
    >


    <%
    url = "http://www.espn.com/main.html"
    set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    xmlhttp.open "POST", url, false
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-
    urlencoded"
    xmlhttp.send "x=1&y=2"
    Response.write xmlhttp.responseText
    set xmlhttp = nothing
    %>

    <http://classicasp.aspfaq.com/general/how-do-i-read-the-contents-of-a-
    remote-web-page.html>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Sep 26, 2007
    #4
  5. Evertjan. wrote:
    > Bob Barrows [MVP] wrote on 26 sep 2007 in
    > microsoft.public.inetserver.asp.general:
    >
    >> BarryX wrote:
    >>> Hi,
    >>>
    >>> How do I simulate this from the server side:
    >>>
    >>> <form name="SearchForm" method="POST" id="SearchForm"
    >>> action="http://SOMEURL/Search.ASP?Parm1=1&Parm2=2">
    >>>

    >
    >
    >> 1. In server-side code, use Microsoft.ServerXMLHTTP
    >> 2. I don;'t think this is possible due to security restrictions. What
    >> are you trying to accomplish?
    >>
    >>

    >
    > <%
    > url = "http://www.espn.com/main.html"
    > set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    > xmlhttp.open "POST", url, false
    > xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-
    > urlencoded"
    > xmlhttp.send "x=1&y=2"
    > Response.write xmlhttp.responseText
    > set xmlhttp = nothing
    > %>
    >
    > <http://classicasp.aspfaq.com/general/how-do-i-read-the-contents-of-a-
    > remote-web-page.html>
    >

    I'm not sure what your point is ... how does this help the OP accomplish
    his task?

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Sep 26, 2007
    #5
  6. BarryX

    Evertjan. Guest

    Bob Barrows [MVP] wrote on 26 sep 2007 in
    microsoft.public.inetserver.asp.general:

    > Evertjan. wrote:
    >> Bob Barrows [MVP] wrote on 26 sep 2007 in
    >> microsoft.public.inetserver.asp.general:
    >>
    >>> BarryX wrote:
    >>>> Hi,
    >>>>
    >>>> How do I simulate this from the server side:
    >>>>
    >>>> <form name="SearchForm" method="POST" id="SearchForm"
    >>>> action="http://SOMEURL/Search.ASP?Parm1=1&Parm2=2">
    >>>>

    >>
    >>
    >>> 1. In server-side code, use Microsoft.ServerXMLHTTP
    >>> 2. I don;'t think this is possible due to security restrictions.
    >>> What are you trying to accomplish?
    >>>
    >>>

    >>
    >> <%
    >> url = "http://www.espn.com/main.html"
    >> set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    >> xmlhttp.open "POST", url, false
    >> xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-
    >> urlencoded"
    >> xmlhttp.send "x=1&y=2"
    >> Response.write xmlhttp.responseText
    >> set xmlhttp = nothing
    >> %>
    >>
    >> <http://classicasp.aspfaq.com/general/how-do-i-read-the-contents-of-a-
    >> remote-web-page.html>
    >>

    > I'm not sure what your point is ... how does this help the OP
    > accomplish his task?
    >


    Oops, I should have quoted Shakespeare, not aspfaq.

    ["A form by any other name ..."]


    <%
    url = "http://www.espn.com/main.html"
    set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    xmlhttp.open "POST", url, false
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-
    urlencoded"
    xmlhttp.send "theFormName=myNewForm"
    Response.write xmlhttp.responseText
    set xmlhttp = nothing
    %>

    [Doing what html can only do in a (possibly hidden) input]


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Sep 26, 2007
    #6
  7. BarryX

    BarryX Guest

    This looks promising Evertjan.

    Will mess with it. Thanks.


    "Evertjan." <> wrote in message
    news:Xns99B7BE4C6C278eejj99@194.109.133.242...
    > Bob Barrows [MVP] wrote on 26 sep 2007 in
    > microsoft.public.inetserver.asp.general:
    >
    > > Evertjan. wrote:
    > >> Bob Barrows [MVP] wrote on 26 sep 2007 in
    > >> microsoft.public.inetserver.asp.general:
    > >>
    > >>> BarryX wrote:
    > >>>> Hi,
    > >>>>
    > >>>> How do I simulate this from the server side:
    > >>>>
    > >>>> <form name="SearchForm" method="POST" id="SearchForm"
    > >>>> action="http://SOMEURL/Search.ASP?Parm1=1&Parm2=2">
    > >>>>
    > >>
    > >>
    > >>> 1. In server-side code, use Microsoft.ServerXMLHTTP
    > >>> 2. I don;'t think this is possible due to security restrictions.
    > >>> What are you trying to accomplish?
    > >>>
    > >>>
    > >>
    > >> <%
    > >> url = "http://www.espn.com/main.html"
    > >> set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    > >> xmlhttp.open "POST", url, false
    > >> xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-
    > >> urlencoded"
    > >> xmlhttp.send "x=1&y=2"
    > >> Response.write xmlhttp.responseText
    > >> set xmlhttp = nothing
    > >> %>
    > >>
    > >> <http://classicasp.aspfaq.com/general/how-do-i-read-the-contents-of-a-
    > >> remote-web-page.html>
    > >>

    > > I'm not sure what your point is ... how does this help the OP
    > > accomplish his task?
    > >

    >
    > Oops, I should have quoted Shakespeare, not aspfaq.
    >
    > ["A form by any other name ..."]
    >
    >
    > <%
    > url = "http://www.espn.com/main.html"
    > set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
    > xmlhttp.open "POST", url, false
    > xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-
    > urlencoded"
    > xmlhttp.send "theFormName=myNewForm"
    > Response.write xmlhttp.responseText
    > set xmlhttp = nothing
    > %>
    >
    > [Doing what html can only do in a (possibly hidden) input]
    >
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)
     
    BarryX, Sep 29, 2007
    #7
  8. BarryX" <> wrote in message
    news:%...
    >>>>>>>>>>>>>>

    It might help if I describe the full problem. I am trying to simulate this:

    <form name="SearchForm" method="POST" id="SearchForm"
    action="Search.ASP?WCI=getPage">
    <input type="hidden" name="PAGE">
    <input type="hidden" name="IsPortfolio">
    <input type="hidden" name="DEL">
    <input type="hidden" name="PropertyID">
    <input type="hidden" name="GTYP" value="0">
    <input type="hidden" name="PER" value="5">
    <input type="hidden" name="RestrictSearch" value="">
    <input type="hidden" Name="StyleSheet" value="">
    <input type="hidden" name="STYPE" value="0">
    <input type="hidden" name="Exit" value="">
    <input type="hidden" name="GID" value="422">
    <input type="hidden" name="CURRENCY" value="GBP">

    So URL parameters AND form parameters going to the POSTed server. This is
    currently triggered from the client side with a click to this:

    javascript:document.SearchForm.PAGE.value='2';document.SearchForm.submit();

    Doing the above works OK so all I want to do is simulate this. The object
    being to bring back page 2 of N pages. A parameter is being passed to the
    server by doing this. So I really need to simulate:
    SearchForm.PAGE.value='2'. The server belongs to someone else so I can't
    change anything at the POSTed end.

    My Server Side code to simulate is as follows:

    Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
    strURL = "?WCI=getPage" & _
    "&IsPortfolio" & _
    "&DEL" & _
    "&PropertyID" & _
    "&GTYP=0" & _
    "&PAGE=2" & _
    "&PER=5" & _
    "&SearchForm.asp" & _
    "&StyleSheet" & _
    "&STYPE=0" & _
    "&Exit" & _
    "&GID=422" & _
    "&CURRENCY=GBP"
    xml.Open "POST","search.asp" & strURL, False

    ' ???????????????? Maybe this is the area
    xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    xml.Send "SearchForm"

    ' Create XML DOM object for the XML
    Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
    xmlDoc.async = False
    xmlDoc.loadXML xml.responseText

    ' Create DOM object for the XSL
    Set xslDoc = Server.CreateObject("Microsoft.XMLDOM")
    xslDoc.async = False

    ' Load a stylesheet
    xslDoc.load (Server.MapPath("Summary.XSLT"))

    ' Convert XML using XSL to HTML
    strHTML = xmlDoc.transformNode(xslDoc)

    ' Send to client
    Response.Write strHTML

    ' All finished
    Set xml = Nothing
    Set xslDoc = Nothing
    Set xmlDoc = Nothing

    Any help appreciated.
    Barry.
    <<<<<<<<<<<

    If you are doing simulations then one tool that is indispensible is
    www.fiddlertool.com

    With this running use a browser to perform a Form post you want to emulate.
    You can now check the recorded session in the tool an you'll see what you
    need to reproduce.

    If you noticed from the example Evertjan gave you when the form method is a
    POST the set of field values should be sent as the entity body of the
    request, IOW a string encoded as URL search section is passed as the
    paremeter of the send function.

    Hence your code should look more like:-

    Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")

    strURL = "http//host.domain.com/search.asp?WCI=getPage"

    strDat = "IsPortfolio=" & _
    "&DEL=" & _
    "&PropertyID=" & _
    "&GTYP=0" & _
    "&PAGE=2" & _
    "&PER=5" & _
    "&RestrictSearch=" & _
    "&StyleSheet=" & _
    "&STYPE=0" & _
    "&Exit=" & _
    "&GID=422" & _
    "&CURRENCY=GBP"

    xml.Open "POST",strURL, False
    xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    xml.Send strDat

    Note that any values that you might concatenate into the data needs to be
    urlencoded,

    BTW, are you sure the form post actually results in an XML response?


    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Sep 30, 2007
    #8
  9. BarryX

    BarryX Guest

    Hi Anthony,

    Yes, definitely XML coming back.

    The example:

    javascript:document.SearchForm.PAGE.value='2';document.SearchForm.submit()

    was provided as a template example to me from the server owner. I could
    simply do this and it would work fine. But then I would have to transform
    the XML at the client side and I want it all on the server side.

    Doing the above, ie. setting PAGE=2 from the client side does not seem to be
    working when issued from the server side. Trouble is, it is very difficult
    to work out why it doesn't work. I just get an empty page back.

    Barry.



    "Anthony Jones" <> wrote in message
    news:...
    >
    > BarryX" <> wrote in message
    > news:%...
    > >>>>>>>>>>>>>>

    > It might help if I describe the full problem. I am trying to simulate

    this:
    >
    > <form name="SearchForm" method="POST" id="SearchForm"
    > action="Search.ASP?WCI=getPage">
    > <input type="hidden" name="PAGE">
    > <input type="hidden" name="IsPortfolio">
    > <input type="hidden" name="DEL">
    > <input type="hidden" name="PropertyID">
    > <input type="hidden" name="GTYP" value="0">
    > <input type="hidden" name="PER" value="5">
    > <input type="hidden" name="RestrictSearch" value="">
    > <input type="hidden" Name="StyleSheet" value="">
    > <input type="hidden" name="STYPE" value="0">
    > <input type="hidden" name="Exit" value="">
    > <input type="hidden" name="GID" value="422">
    > <input type="hidden" name="CURRENCY" value="GBP">
    >
    > So URL parameters AND form parameters going to the POSTed server. This is
    > currently triggered from the client side with a click to this:
    >
    >

    javascript:document.SearchForm.PAGE.value='2';document.SearchForm.submit();
    >
    > Doing the above works OK so all I want to do is simulate this. The object
    > being to bring back page 2 of N pages. A parameter is being passed to the
    > server by doing this. So I really need to simulate:
    > SearchForm.PAGE.value='2'. The server belongs to someone else so I can't
    > change anything at the POSTed end.
    >
    > My Server Side code to simulate is as follows:
    >
    > Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
    > strURL = "?WCI=getPage" & _
    > "&IsPortfolio" & _
    > "&DEL" & _
    > "&PropertyID" & _
    > "&GTYP=0" & _
    > "&PAGE=2" & _
    > "&PER=5" & _
    > "&SearchForm.asp" & _
    > "&StyleSheet" & _
    > "&STYPE=0" & _
    > "&Exit" & _
    > "&GID=422" & _
    > "&CURRENCY=GBP"
    > xml.Open "POST","search.asp" & strURL, False
    >
    > ' ???????????????? Maybe this is the area
    > xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    > xml.Send "SearchForm"
    >
    > ' Create XML DOM object for the XML
    > Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
    > xmlDoc.async = False
    > xmlDoc.loadXML xml.responseText
    >
    > ' Create DOM object for the XSL
    > Set xslDoc = Server.CreateObject("Microsoft.XMLDOM")
    > xslDoc.async = False
    >
    > ' Load a stylesheet
    > xslDoc.load (Server.MapPath("Summary.XSLT"))
    >
    > ' Convert XML using XSL to HTML
    > strHTML = xmlDoc.transformNode(xslDoc)
    >
    > ' Send to client
    > Response.Write strHTML
    >
    > ' All finished
    > Set xml = Nothing
    > Set xslDoc = Nothing
    > Set xmlDoc = Nothing
    >
    > Any help appreciated.
    > Barry.
    > <<<<<<<<<<<
    >
    > If you are doing simulations then one tool that is indispensible is
    > www.fiddlertool.com
    >
    > With this running use a browser to perform a Form post you want to

    emulate.
    > You can now check the recorded session in the tool an you'll see what you
    > need to reproduce.
    >
    > If you noticed from the example Evertjan gave you when the form method is

    a
    > POST the set of field values should be sent as the entity body of the
    > request, IOW a string encoded as URL search section is passed as the
    > paremeter of the send function.
    >
    > Hence your code should look more like:-
    >
    > Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
    >
    > strURL = "http//host.domain.com/search.asp?WCI=getPage"
    >
    > strDat = "IsPortfolio=" & _
    > "&DEL=" & _
    > "&PropertyID=" & _
    > "&GTYP=0" & _
    > "&PAGE=2" & _
    > "&PER=5" & _
    > "&RestrictSearch=" & _
    > "&StyleSheet=" & _
    > "&STYPE=0" & _
    > "&Exit=" & _
    > "&GID=422" & _
    > "&CURRENCY=GBP"
    >
    > xml.Open "POST",strURL, False
    > xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    > xml.Send strDat
    >
    > Note that any values that you might concatenate into the data needs to be
    > urlencoded,
    >
    > BTW, are you sure the form post actually results in an XML response?
    >
    >
    > --
    > Anthony Jones - MVP ASP/ASP.NET
    >
    >
     
    BarryX, Oct 1, 2007
    #9
  10. "BarryX" <> wrote in message
    news:...
    >
    > Hi Anthony,
    >
    > Yes, definitely XML coming back.
    >
    > The example:
    >
    > javascript:document.SearchForm.PAGE.value='2';document.SearchForm.submit()
    >
    > was provided as a template example to me from the server owner. I could
    > simply do this and it would work fine. But then I would have to transform
    > the XML at the client side and I want it all on the server side.
    >
    > Doing the above, ie. setting PAGE=2 from the client side does not seem to

    be
    > working when issued from the server side. Trouble is, it is very difficult
    > to work out why it doesn't work. I just get an empty page back.
    >


    1) Install fiddler.
    2) Build a VBScript file to emulate POST (use XmlHttp not ServerXmlHttp).
    3) With fiddler use suppliers example of making post.
    4) Use VBScript file to make the post.
    5) In fiddler compare POSTs made by the two approaches
    6) Adjust VBScript until its requests matches the suppliers example
    7) Tweak script to use ServerXMLHTTP and check it still works
    8) Install code into ASP.




    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, Oct 2, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Al Cadalzo

    How to simulate a form post?

    Al Cadalzo, Feb 17, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    7,597
    Al Cadalzo
    Feb 17, 2004
  2. delph
    Replies:
    3
    Views:
    1,370
    Andrea Desole
    May 13, 2005
  3. dast

    Simulate post at webpage

    dast, Sep 15, 2005, in forum: C++
    Replies:
    2
    Views:
    333
    =?ISO-8859-1?Q?Stefan_N=E4we?=
    Sep 15, 2005
  4. BarryX

    Simulate Form Post on Server Side

    BarryX, Sep 26, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    532
    Patrice
    Sep 26, 2007
  5. nospam
    Replies:
    1
    Views:
    453
    sloan
    Oct 13, 2007
Loading...

Share This Page