July 19, 2005 at 12:49 pm
We currently have an internal web site we use to get information about our customers. For example, I got to the site, enter in a customer SSN and the page returns info about the customer in XML, such as name, address etc.... I think I have fugured out how to take the XML: doc and get it into the database. however I can't figure out how to programtically send the http request to the page a retrieve the XML.
Any thoughts?
July 20, 2005 at 1:59 am
This is a very simple example of a vbscript that periodically requests an xml file at a url and saves the contents. Obviously if you are using .net you should rather be looking at HttpWebRequest class. I've included a code sample for that also but it will obviously have to be taken out of context.
Hope one of these helps point you in the right direction.
--------------------------------------------------------------------------
vbscript
--------------------------------------------------------------------------
option explicit
on error resume next
dim f
dim fs
dim fso
dim filedat
dim url
url = "http://www.qmissxmlservice.org.uk/XMLFiles/XmlServiceCMGD/content.xml"
filedat = "D:\XML\TestFileName_CMGD.XML"
set fs=createobject("Scripting.FileSystemObject")
set f=fs.opentextfile(filedat,8,true)
Set theHTML = CreateObject("MICROSOFT.XMLHTTP")
theHTML.open "GET", url, False
theHTML.send
f.write theHTML.responseText
f.close
--------------------------------------------------------------------------
--------------------------------------------------------------------------
C# .net
--------------------------------------------------------------------------
public XmlDocument LoadFeed(bool forceReload)
{
XmlDocument rssDoc = null;
if(forceReload || cacheObj==null || (cacheObj!=null && cacheObj.IsInCache()==false))
{
WebProxy proxyObject = System.Net.WebProxy.GetDefaultProxy();
GlobalProxySelection.Select = proxyObject;
proxyObject.Credentials = CredentialCache.DefaultCredentials;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
XmlTextReader reader = new XmlTextReader(response.GetResponseStream());
reader.XmlResolver = null;
rssDoc = new XmlDocument();
rssDoc.Load(reader);
}
if(cacheObj!=null && rssDoc==null)
rssDoc = cacheObj.GetFromCache();
else
{
if(cacheObj!=null)
{
cacheObj.CacheKey = cacheObj.MakeNewCacheKey(this.Url);
cacheObj.SaveToCache(rssDoc);
}
}
return rssDoc;
}
}
--------------------------------------------------------------------------
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy