Web Client


The cWebClient class

Easy web access for Visual DataFlex inspired by the .NET WebClient class. Meant to be easy and intuitive. Perfect for working with REST services or any web based content in general.

Dependecies

Members

Public methods

Method Type Parameters Description
RequestHeader Procedure Set String sHeaderName
String sHeaderValue
Set request headers for the request.
ResponseHeader Function String sHeaderName
Returns String
Get response headers for the last request.
ClearRequestHeaders Procedure no parameters Clear all request headers.
DownloadString Function String sUrl
Returns String
Download url content using the GET method.
UploadString Function String sUrl
String sData
Returns String
Upload data to an url using the POST method.
DownloadFile Function String sUrl
String sFileName
Returns Boolean
Download url content to a given file using the GET method.
UploadFile Function String sUrl
String sFile
Returns String
Upload file contents to an url using the POST method.

Public properties

Property Default value Description
psProxy blank A proxy server for requests.
psUserName blank Username for server log on.
psPassword blank Password for server log on.
psUserAgent "Visual Dataflex cWebClient" The user agent for requests.
piHttpPort 80 Default port for HTTP requests.
piHttpsPort 443 Default port for HTTPS requests.
piFtpPort 21 Default port for FTP requests.
piFtpsPort 21 Default port for FTPS requests.
piUploadEncoding cwcUTF8 Default encoding for uploaded content. The cWebClient does the conversion automatically.
piDownloadEncoding cwcUTF8 Default encoding for downloaded content. The cWebClient does the conversion automatically.
piResponseStatus 0 The HTTP response status code for the last request.

Code examples

A simple GET request

The default request accept header is text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Calling the Google Geocoding API

In most cases you can work with the out-of-the-box settings. Although remember that WCF services are more strict on the request and response header values. You might have to set Accept and Content-Type headers manually.

A simple POST request

The default request content type for the upload methods is application/x-www-form-urlencoded. This makes it easy to pass key=value data to the url. But if you wanna upload, let's say, XML then you need to change the Content-Type for the request header to text/xml or application/xml

Download it

Share

4 thoughts on Web Client

  1. Small correction to your code
    Roel

    Function GeoXml String sAddress Returns String
    Handle hWebClient
    String sData
    Get Create U_cWebClient to hWebClient
    Get DownloadString of hWebClient (SFormat(“http://maps.googleapis.com/maps/api/geocode/xml?address=%1&sensor=true”, sAddress)) to sData
    If ((piResponseStatus(hWebClient)) 200) Begin
    Send UserError “Could not download data” “Request Error”
    End
    Send Destroy of hWebClient
    Function_Return sData
    End_Function

    Procedure OnClick
    String sGeoInfo
    Get GeoXml “Stockholm” to sGeoInfo
    End_Procedure

  2. Hey,
    Great client. Really handy.
    Thank you very much for it.

    One question/problem:
    – Can I DownloadString a big website? (how?)
    -> For me, it caps the download at 65k characters (maybe because this is the max. number of chars in a String)
    -> Can I download chunks of data instead?

    Did you (or anyone else) have this problem?
    Can you help, or do I have to use “set_argument_size”

    (I’ve only developed with DataFlex a few years so please forgive me if this is a beginners-task)

    Thanks in advance.

    • Hi, thanks for the comment. You have to use Set_Argument_Size for now. The return value for DownloadString is a string, so even if the data is downloaded in chunks you’d still end up having to fit it into a string.

Leave a Reply

Your email address will not be published. Required fields are marked *