Forwarding POSTs

Post Reply
vidar.ramdal
Posts: 9
Joined: Fri Dec 15, 2000 12:53 pm

Forwarding POSTs

Post by vidar.ramdal »

I want to obtain values from a unknown form and SUBMIT them to another URL. The problem is that I don't know the names of the form variables, or even how many variables there is to be posted. I figure I can't use SUBMIT to post these values, since SUBMIT takes names and values of variables as arguments.
However, I believe the sollution could be adding HTTP headers containing the data, but I'm not too much of an HTTP expert to figure this out. Any suggestions?

<a name=formpost PUBLIC>
<varinfo LIST CONTENT> <!-- obtain names of variables -->
<LOOP $vars>
<getvar $vars>
<urlcp header $vars $ret> <!-- this doesn't work, but it's probably not the correct HTTP syntax -->
</LOOP>

<submit METHOD=post URL=$theurl var=val> <!-- this is the problem. SUBMIT must have names and values, and I don't know how many variables there are>

<!-- fetch, format and display results -->
</a>
User avatar
John
Site Admin
Posts: 2597
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Forwarding POSTs

Post by John »

You are on the right track, however the data can not be sent via HTTP headers. The form of SUBMIT that you want to be using is:

<submit METHOD=POST URL=$theurl DATA=$data>

where you would need to build up $data. Something similar to the following should do the job:

<varinfo list CGI><$vars=$ret>
<loop $vars>
<getvar $vars><$vals=$vals>
<loop $vals>
<strfmt "%U=%U" $vars $vals><$items=$items $ret>
</loop>
</loop>
<sum "%s&" $items><$data=$ret>
<submit METHOD=POST URL=$theurl DATA=$data>
John Turnbull
Thunderstone Software
vidar.ramdal
Posts: 9
Joined: Fri Dec 15, 2000 12:53 pm

Forwarding POSTs

Post by vidar.ramdal »

Thank you, that did the trick! However, another tricky problem occured:
The server I'm POSTing to sends back a cookie, which does not reach the end user, but seem to disappear somewhere in cyberspace. How can I intercept this cookie, and send it correctly to the user?
User avatar
John
Site Admin
Posts: 2597
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH
Contact:

Forwarding POSTs

Post by John »

After you submit you can use <urlinfo header Set-Cookie> to find the cookie that the server sets. You can use <header> to send a header back to the user. However cookies are associated with the server that sent them which may cause some issues. The use of the DOMAIN= option to <header> may help.
John Turnbull
Thunderstone Software
Post Reply