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
...
October 1st, 2009 - 06:23
Hi Darren, Your xml is not valid Paris
October 1st, 2009 - 06:40
Tnhaks for catching that. I just updated it.