Code Reference A collection of code for my reference (and perhaps other people too)

10Sep/092

GET and POST using ASP

In these examples I am calling a WCF service. Many legacy projects out on the net are still using ASP.

POST example with ASP

xmlToSend = "<?xml version=""1.0"" encoding=""utf-8"" ?><InputXMLObject xmlns=""http://schemas.datacontract.org/2004/07/MyService""><FirstName>Darren</FirstName><LangCode>UK</LangCode><LastName>Sullivan</LastName><Address>123 Rue de Nowhere</Address><City>Paris</City></InputXMLObject>"

postUrl = "http://myurl.com/MyService.svc/AddPerson"
Dim HttpReq
Set HttpReq = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
HttpReq.Open "POST", postUrl, False
HttpReq.SetRequestHeader "Content-Type", "application/xml"	'"application/x-www-form-urlencoded"
HttpReq.Send xmlToSend
PostXMLResponse = HttpReq.ResponseText

GET example with ASP

getUrl = "http://MyUrl/MyService.svc/AddPerson?FirstName=Darren&LastName=Sullivan&Address=123 Rue de Nowhere&City=Paris&langCode=UK"

Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", getUrl, False
xmlhttp.setRequestHeader "Content-type", "text/xml"
xmlhttp.send()
GetXMLResponse = xmlhttp.responseText

Process the XML result

Set SourceObj = Server.CreateObject("MSXML2.DOMDocument.6.0")
SourceObj.async = false
SourceObj.setProperty "SelectionLanguage", "XPath"
'SourceObj.loadXML( GetXMLResponse ) ' For the GET call
SourceObj.loadXML( PostXMLResponse ) ' For the POST call

Dim NewRecordID, Success, ErrorString

set NewRecordID	= SourceObj.documentElement.selectSingleNode("//RecordID")
set Success = SourceObj.documentElement.selectSingleNode("//Success")
set ErrorString = SourceObj.documentElement.selectSingleNode("//ErrorString")

if not ErrorStringis nothing then
	ErrorText = ErrorString.text
else
	ErrorText = ""
end if
...
Tagged as: Leave a comment
Comments (2) Trackbacks (1)
  1. Hi Darren, Your xml is not valid Paris

  2. Tnhaks for catching that. I just updated it.


Leave a comment