Solved

Is there an ASP equivalent for cfhttp?

Posted on 2013-02-06
8
706 Views
Last Modified: 2013-02-06
I have a Coldfusion page I am converting to ASP.

What would be the syntax for ASP for this?

<cfhttp url="#cgiConnector#" method="get">
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
<cfhttpparam type="Header" name="TE" value="deflate;q=0">
</cfhttp>

Is there an ASP equivalent for cfhttp?
0
Comment
Question by:Donnie Walker
  • 4
  • 4
8 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 38859898
This should get you what you want. PostData is the data you want to send over.

Set ServerXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
ServerXmlHttp.open "POST", "http://www.domain.com/page.asp"
ServerXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
ServerXlHttp.setRequestHeader "Content-Length", Len(PostData)
ServerXmlHttp.send PostData
0
 

Author Comment

by:Donnie Walker
ID: 38859925
Is this for Classic ASP?

How do I get the response back from http://www.domain.com/page.asp?
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 38859945
yup, this is for classic asp. To get the response back, you would use the ResponseText (assuming you're expecting plain text back, if not I included the property to use for xml)  property of the ServerXmlHttp object:

Set ServerXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
ServerXmlHttp.open "POST", "http://www.domain.com/page.asp"
ServerXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
ServerXlHttp.setRequestHeader "Content-Length", Len(PostData)
ServerXmlHttp.send PostData

If ServerXmlHttp.status = 200 Then
      TextResponse = ServerXmlHttp.responseText
      XMLResponse = ServerXmlHttp.responseXML
Else
      ' Handle missing response or other errors here
End If

Set ServerXmlHttp = Nothing
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:Donnie Walker
ID: 38860012
ok, so if the ServerXmlHttp.status is 200 then that is an error?

Then if the response back is a url then the else would be this:

      response.redirect ServerXmlHttp.responseText
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 38860037
a status of 200 means NO error has occured, it's basically a check to make sure everything worked properly on the remote servers end.

You could do the redirect as you have above, but I would assign the responseText to a variable, close and destroy all of your objects, THEN do the redirect. This ensures no unneeded objects remain in memory before you go to another page.
0
 

Author Comment

by:Donnie Walker
ID: 38860682
When I do this:

Set ServerXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
ServerXmlHttp.open "POST", "https://e5.onthehub.com/WebStore/Security/AuthenticateUser.aspx?username=dw100&email=dw100@college.edu&key=85515708&shopper_ip=10.1.1.117&last_name=Doe&first_name=John&academic_statuses=staff,students,faculty"
ServerXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
ServerXlHttp.setRequestHeader "Content-Length", Len(PostData)
ServerXmlHttp.send PostData

If ServerXmlHttp.status = 200 Then
      TextResponse = ServerXmlHttp.responseText
      XMLResponse = ServerXmlHttp.responseXML
      response.redirect ServerXmlHttp.responseText
End If

Set ServerXmlHttp = Nothing

I get this error:

Microsoft VBScript runtime error '800a01a8'

Object required: ''

The error is on line:
ServerXlHttp.setRequestHeader "Content-Length", Len(PostData)
0
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 38860838
you have a typo in between the x and l :)

should be:

ServerXmlHttp.setRequestHeader "Content-Length", Len(PostData)
0
 

Author Closing Comment

by:Donnie Walker
ID: 38860916
Thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now