NetworkRequest [examples]

The NetworkRequest class in the Lianja Framework provides support for http, https and ftp reading and writing files and other data such as making OData requests.

It supports uploading and downloading of files with (optional) authenticated requests.

It can be used by any of the supported scripting languages; Visual FoxPro, PHP, Python or JavaScript.

If the async property is set to true, then you can subclass it and define an event handler called finished(data as character) that is passed the data received or the name of the filename containing the data when the request completes. If async is false then the operation is performed synchronously.

When using it in async mode the progressChanged(currentvalue as numeric, totalsize as numeric) event handler is called allowing you to provide progress feedback to the user during the request.

Additionally, in async mode you can call oRequest.isFinished() to determine if the request has completed.

You can verify that you have a valid network connections using oRequest.networkAccessible() and check for errors using oRequest.errorNumber and oRequest.errorString

oRequest = createObject("networkrequest")
oRequest.async = .f.
oRequest.username = "yourname"
oRequest.password = "yourpassword"
oRequest.setHeader("name", "value")
oRequest.setHeader("name2", "value")
oRequest.getFile("http://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.getFile("https://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.getFile("ftp://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.putFile("http://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.putFile("https://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.putFile("ftp://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.postFile("http://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.postFile("https://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
oRequest.postFile("ftp://www.anywhere.com/filename.xxx?arg=value&arg2=value", filename)
m_string = oRequest.getData("http://www.anywhere.com/filename.xxx?arg=value&arg2=value")
oRequest.putData("http://www.anywhere.com/filename.xxx?arg=value&arg2=value", "send this to the server")
oRequest.postData("http://www.anywhere.com/filename.xxx?arg=value&arg2=value", "send this to the server")

You can use this class very effectively when working with OData services in the Cloud.

https://www.lianja.com/doc/index.php/Web_Integration


 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.