Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.0   6.1   6.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3    Statistic  

CURL.ReceiveText

Receives raw data on a connection as text.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
CURL 7.2 Yes Yes Yes Yes Yes

MBS( "CURL.ReceiveText"; Handle; BytesToRead { ; Encoding } )

Parameters

Parameter Description Example value
Handle The CURL session handle. $curl
BytesToRead Maximum number of bytes to read. 1000
Encoding Optional
The text encoding for result.
Default is UTF-8.
Possible encoding names: ANSI, Arabic-Mac, Arabic-Win, Baltic-Win, CentralEurope-Mac, ChineseSimp-Mac, ChineseSimp-Win, ChineseTrad-Mac, ChineseTrad-Win, Cyrillic-Mac, Cyrillic-Win, EasternEurope-Win, Greek-Mac, Greek-Win, Hebrew-Mac, Hebrew-Win, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-15, Korean-Johab, Korean-Mac, Korean-Win, Latin1, Mac, Native, ShiftJIS-Mac, ShiftJIS-Win, Turkish-Mac, Turkish-Win, UTF-8, DOS or Windows. Pass native to use the native encoding of the current platform.
"UTF8"

Result

Returns OK or error.

Description

Receives raw data on a connection as text.
This function receives raw data from the established connection. You may use it together with SendData to implement custom protocols using libcurl. This functionality can be particularly useful if you use proxies and/or SSL encryption: libcurl will take care of proxy negotiation and connection set-up.

BytesToRead is the maximum amount of data you want to read now. The function returns the text read, which can be less than requested.

To establish the connection, set OptionConnectOnly = true before calling Perform. Note that ReceiveData does not work on connections that were created without this option.

The call will return CURLE_AGAIN if there is no data to read - the socket is used in non-blocking mode internally. When CURLE_AGAIN is returned, wait for data to arrive.

Wait on the socket only if ReceiveData returns CURLE_AGAIN. The reason for this is libcurl or the SSL library may internally cache some data, therefore you should call ReceiveData until all data is read which would include any cached data.

Furthermore if you wait on the socket and it tells you there is data to read, ReceiveData may return CURLE_AGAIN if the only data that was read was for internal SSL processing, and no other data is available.

On success, sets error code to CURLE_OK (0) and returns the text.
On failure, returns zero and error code is set to the appropriate error code.

The function may return CURLE_AGAIN. In this case, use your operating system facilities to wait until data can be read, and retry.

Reading exactly 0 bytes indicates a closed connection.

If there's no socket available to use from the previous transfer, this function returns CURL_EUNSUPPORTED_PROTOCOL.

Please use CURL.ErrorCode to query error after you used this function.

Examples

Loop and read text from socket:

Set Variable [$received; Value:""]
    Loop
        Pause/Resume Script [Duration (seconds): ,1]
        Set Variable [$r; Value:MBS( "CURL.ReceiveText"; $curl; 100000; "UTF-8")]
        Set Variable [$errorCode; Value:MBS( "CURL.ErrorCode"; $curl)]
        If [GetAsNumber ( $errorCode ) = 81]
            #wait
        Else If [GetAsNumber ( $errorCode ) = 0]
            #got some data
            Set Variable [$received; Value:$received & $r]
            Exit Loop If [$r = ""]
        Else
            #error
            Exit Loop If [1]
        End If
    End Loop
    Set Variable [$received2; Value:MBS( "Text.ReplaceNewline"; $received; 1)]
    Set Field [CURL Low Level Sockets::Data Received; $received2]

See also

Example Databases


CURL.ReceiveData   -   CURL.Reset

Feedback: Report problem or ask question.




Links
MBS FileMaker Plugins