Wiki Home

XML HTTP


Namespace: VFP
A popular method of retrieving data from web sites is using the XMLHTTP function (AJAX). Here is a simple example of using the COM object within Visual Foxpro

#DEFINE	HTTPSTATUS_OK			200
#DEFINE	HTTPSTATUS_CREATED		201
#DEFINE	HTTPSTATUS_ACCEPTED		202
#DEFINE	HTTPSTATUS_MULTISTATUS		207
#DEFINE	HTTPSTATUS_BADREQUEST		400
#DEFINE	HTTPSTATUS_UNAUTHORIZED		401
#DEFINE	HTTPSTATUS_FORBIDDEN		403
#DEFINE	HTTPSTATUS_NOTFOUND		404
#DEFINE	HTTPSTATUS_INTERNALSERVERERROR	500

oHTTP = CreateObject("Microsoft.XMLHTTP")

oHTTP.Open("GET", 'http://fox.wikis.com/wc.dll?Wiki~WikiRss&details=1', .F.)
oHTTP.Send()

? oHTTP.status
? oHTTP.responseText


more: http://fox.wikis.com/wc.dll?Wiki~WikiRssDocumentation

forgot to mention:
TRY
oHTTP.Send()
CATCH
* error handling code here.
ENDTRY
stops the XML throwing a OLE error (stuart)
Railing Tangga
Aksesoris Mobil
Rental Forklift
Toko Bunga Murah


to use POST instead of GET

oHTTP = CreateObject("Microsoft.XMLHTTP")

oHTTP.Open("POST", "http://fox.wikis.com/wc.dll", .F.)
oHTTP.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
oHTTP.Send('Wiki~WikiRss&details=1')

*NOTE: If calling oHTTP.Send from within an object method,
* you may have to help VFP provide the parameter in the Variant format by adding extra parentheses, like this:
lcData = 'fieldname=fieldvalue'
oHTTP.Send( (lcData) )  && Without the double parentheses, I get the error "the parameter is incorrect"

? oHTTP.status
? oHTTP.responseText

use oHTTP.responseBody when grabbing binary data (stuarthurley)

How do I then convert the "GET" oHTTP.responseText that your example uses into a cursor? I've tried XMLTOCURSOR(oHTTP.responseText(), "csrWIKI") but it only shows 1 record. The oHTTP.responseText appears to contain much more.

can i use this instead "InternetExplorer.Application" ?! .. if yes then how ?! consider the code:

LOCAL oDoc, oElem
oDoc=loIE.document
oElem=oDoc.getElementById("poem")
x = oElem.innerText

where "poem" is the id of a div tag
Category XML Category ActiveX Category Code Samples

Agen Domino99
Poker Online Uang Asli
( Topic last updated: 2016.04.10 10:47:47 PM )