Forum Moderators: open

Message Too Old, No Replies

ASP ServerXMLHTTP

Redirecting to the POST response

         

jonparker83

10:13 am on May 5, 2005 (gmt 0)

10+ Year Member



Hi all,

I usually do any coding in PHP as the only programming I've done is C and it seemed more logical to me

I now have a the problem of trying to replicate a PHP script in ASP and have run into a problem

I'm basically using ServerXMLHTTP to post data to a remote web page that is not under my control and after I have POSTed the data, I woudl like to redirect to the remote page so that I can view the response

Here is my code:

-----------------------------------------------

Dim objXmlHttp1
Set objXmlHttp1 = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp1.open "POST","https://example.com/cgi-bin/CcxBarclaysEpdq.e",False
objXmlHttp1.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
objXmlHttp1.send epdqVars

Dim strEPDQ1
strEPDQ1 = objXmlHttp1.responseText
Set objXmlHttp1 = Nothing

Response.Status = "307 Temporary Redirect"
Response.AddHeader "Location", "https://example.com/cgi-bin/CcxBarclaysEpdq.e"
Response.End

-----------------------------------------------------

As you can see, ive tried to alter the headers after performing the POST to redirect the page

This *does* redirect the page but the page shown does not reflect the data sent via the POST

Any advice on the code ive used or alternative approaches would be greatly appreciated!

Cheers

[edited by: Xoc at 3:51 am (utc) on May 11, 2005]
[edit reason] Use example.com for examples [/edit]

mrMister

11:16 am on May 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might want to try programming your ASP in JScript rather than VBScript.

JavaScript is derived from C, so you'll find the syntax easier.

I'm not sure how you'd go about this in any on the server side in any environment. Can you post your PHP source so I can see how you're doing it there.

I can think of two ways of going about this off the top of my head.

The first is to write the output the remote server's response to the Response object of ASP.

The second is to use client side Javascript to fire an event method on a form that you've populated in server side ASP.

jonparker83

12:41 pm on May 5, 2005 (gmt 0)

10+ Year Member



Thanks for the reply, here is my php code

-------------------------------------------------

// perform the POST using 3rd party snoopy class here then....

header("HTTP/1.0 307 Temporary redirect");
header("Location: [example.com...]
exit();

---------------------------------------------------

[edited by: Xoc at 3:49 am (utc) on May 11, 2005]
[edit reason] Use example.com for examples [/edit]

jonparker83

12:46 pm on May 5, 2005 (gmt 0)

10+ Year Member



another thing..

As you mentioned for your first possible solution, i've already actually tried the following code:

-----------------------------------------

response.Write(strEPDQ1)

-----------------------------------------

this output the html response as I would have expected but all the image/link paths were broken

mattglet

1:03 pm on May 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is the epdqVars value coming from a form post, or are you building it dynamically? If it's from a form, you can just change the action to post to that URL you're using.

BTW, you should change your URLs to example.com. We discourage people posting the true URLs.

mrMister

1:32 pm on May 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As you mentioned for your first possible solution, i've already actually tried the following code:

response.Write(strEPDQ1)

Use this instead:

Response.write(Replace(strEPDQ1,"<head>","<head><base href=""https://example.com/cgi-bin/"">"))

Check the actual source though and make sure that <head> is in the correct case.

[edited by: Xoc at 3:51 am (utc) on May 11, 2005]
[edit reason] Use example.com for examples [/edit]

jonparker83

8:13 am on May 6, 2005 (gmt 0)

10+ Year Member



Sorry didn't realise about posting actual URLs!

The POST data is being built with a combination of constants and database data

Changing the base to the links worked perfectly (as far as I can see) so thank you very much for that!

I'd never even heard of specifying the base in the head tag before! :)