Solved

Is there an ASP equivalent for cfhttp?

Posted on 2013-02-06
8
686 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 32

Expert Comment

by:Big Monty
Comment Utility
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
Comment Utility
Is this for Classic ASP?

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

Expert Comment

by:Big Monty
Comment Utility
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
 

Author Comment

by:Donnie Walker
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 32

Expert Comment

by:Big Monty
Comment Utility
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
Comment Utility
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 32

Accepted Solution

by:
Big Monty earned 500 total points
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

9 Experts available now in Live!

Get 1:1 Help Now